How to centre a div and how to centre the contents of a div
1. I want to centre a DIV
2. I want to centre the contents of a DIV
I did a google and it seems this is not straight forward!
I came across several different answers
I'd be happy to go with one of the answer: but most of these are dated more than 5 years ago - I assumed that the code maybe old and outdated now?
Can someone give me a definitive answer to how to centre a DIV and separately, how to centre the contents of a DIV
I disagree - if the content of the div includes child divs, images, tables floated, unfloated, css positioned or whatever then text-align: center on its own is not going to center the div contents.
As mentioned earlier, we need to know what the contents are before they can be centred using css.
Need to re-read what I said. The text align only aligns the text. The main div will be centered and the contents, meaning the related text only, will be centered.
When I said that's all there is, I was saying you don't need all the margin: 0 auto 0 auto; coding either. Any other divs inside the div that was being asked about is another matter as stated, but OP didn't asked about div containers inside of div containers. I like to stick to just what is asked without making things complex. If clarification is needed, then I will clarify or answer further questions about the subject.