Today, Xiao Tao accidentally found a problem, that is, some pages in IE browser when the margin:0 Auto page can not be centered, other browsers are normal, search for the discovery of two solutions:
1. Change DOCTYPE to XHTML 1.0 tranditional (Invalid under HTML 4.01)
2, add div outside the block, and apply text-align:center to this div
Add a 3C invocation declaration
HTML code
| The code is as follows |
Copy Code |
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
|
I don't want to add
There is also a saying that to add a property to the body
HTML code
| The code is as follows |
Copy Code |
| Text-align:center; |
I don't want to add it, it's a little steep.
Since this attribute can be added to the body, why not a div with this attribute on the outer bread?
Test, through
| The code is as follows |
Copy Code |
<div style= "Text-align:center;" > <div style= "margin:0 auto;" > Center </div> </div>
|
A friend on the internet said
You can try using absolute positioning to half of the parent element, position:absolute;left:50%; Then use the left negative margin of half the width of the centered element, for example, the center element width is 760px; margin-left:-360px
Summary:
The difference between IE6 and Firefox, IE's text-align:center can make it contain the block elements and inline elements and text content centered.
Under Firefox, text-align:center only contains inline elements and text content that is centered.
Margin:0 Auto Enables a block element to be centered, but does not center inline elements, which are the same under Firefox and IE6. For IE6 Previous versions of browsers need to match the text-align:center of their parent elements in order to center, you also use for IE under the margin : 0 Auto Page can not center the problem headache?