Home>Article>Web Front-end> css:margin:0 auto can’t be centered in ie8
Today I wrote a div, using margin:0 auto; to define its attributes and center it, but it turned out to be invalid.
At first, I thought it was a code conflict in the css. I checked it several times and found that there was no problem. Then I tested it with Firefox and Google Chrome and found that it was centered. . .
It seems to be a browser compatibility issue. I suddenly remembered that I am using win7 and ie has been upgraded to ie8. It seems that the problem is the compatibility of ie8. Baidu. . . .
The solution is copied below:
To achieve centering under IE6, 7, and Firefox, margin: auto is generally used to achieve it, but under IE8, this is not enough. Two solutions are provided:
Method 1 (recommended):
First, the document type must be set at the top of the page:
and add:
in the head即可!
Method 2:
Body settings {text-align:center;width:100%;}
Include all divs in c51f4459fcf422a08b11ee79272896f5 , wrap is set as follows:
#wrap { text-align:left; width:***; margin:0 auto; }
and add in the head:
That’s it!
Method three:
Use bacbf9e1ad7f40415ce1670e31edfee3adca8a5fa06ffeafb062c2e3f274b930 to replace the wrap layer in the second one.
The above is the detailed content of css:margin:0 auto can’t be centered in ie8. For more information, please follow other related articles on the PHP Chinese website!