I am having problems getting text within a table to appear centered in IE.
In Firefox 2, 3 and Safari everything work fine, but for some reason, the text doesn't appear centered in IE 6 or 7.
I'm using:
h2 {
font: 300 12px "Helvetica", serif;
text-align: center;
text-transform: uppercase;
}
I've also tried adding margin-left:auto;
, margin-right:auto
and position:relative;
to no avail.
CSS text-align property should be declared on the parent element and not the element you are trying to center. IE uses text-align: center property to center text. Firefox uses margin: 0 auto and it has to be declared on the element you are trying to center.
<div style="text-align: center">
<h2 style="margin: 0 auto">Some text</h2>
</div>
The table cell needs the text-align: center.
Might be a typo, but you are missing a semicolon here:
margin-left:auto; margin-right:auto position:relative;
Should be:
margin-left:auto; margin-right:auto; position:relative;
If that doesn't work, make sure the element you are trying to center the text on has some width. Try setting the width to 100% and see if anything changes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With