Centering text Using CSS doesn't work in IE

I'm having trouble getting the text inside the table to be centered in IE.

In Firefox 2, 3 and Safari, everything works fine, but for some reason the text does not appear centered in IE 6 or 7.

I use:

h2 {
  font: 300 12px "Helvetica", serif; 
  text-align: center; 
  text-transform: uppercase;
}

I also tried to add margin-left:auto;, margin-right:autoandposition:relative;

to no avail.

+3
source share
6 answers

The table cell requires text-align: center.

+3
source

text-align CSS , , . IE text-align: center . Firefox margin: 0 auto, , .

<div style="text-align: center">
    <h2 style="margin: 0 auto">Some text</h2>
</div>
+4

, , :

margin-left:auto; margin-right:auto position:relative;

:

margin-left:auto; margin-right:auto; position:relative;

, , , , . 100% , - .

+1

text-align: center , (h2) - , .

, IE font, ?

0

text-align: center div/td, h2.

<table style = "width:400px;border:solid 1px;">
    <tr>
        <td style = "text-align:center;"><h2>hi</h2></td>
    </tr>
</table>

edit: wow, stackoverflow !

0

If you can / want to use flexbox, you can also use the following.

display: flex;
justify-content: center;
align-items:center
0
source

Source: https://habr.com/ru/post/1696920/


All Articles