I read that the <center> tag is deprecated, however I cannot find any real equivalent to it in CSS. text-align works for text but not other elements, and auto margins only work if you know the width of the container (so not a solution if you don’t know the width in advance). So is there any real equivalent to this <center> tag?
I read that the <center> tag is deprecated, however I cannot find any real
Share
text-alignshould work for other kinds of elements. Does this work?Edit Three Years Later 😀
margin: auto;also makes the top and bottom margins “auto”. That might not be what you want. Alternatively you could have something like:This particular example will center the text horizontally while hardwiring the upper and lower margins to 3 pixels.
One can also say something like
margin: 3px auto 3px auto;but I prefer spelling out the directions explicitly, as I can never quite remember what the order of the parameters are if I put them all on the onemargin:setting.