Is the开发者_如何学运维re a non-javascript way to center the very first container div of a page which would work with IE, FF as well as chrome?
margin:0 auto;
does not work in IE8 :(
That should most certainly work in IE8, the reason why it doesn't work for you could be that your IE is in quirks mode, possibly due to a missing DocType. Try this:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div style="width:50%;margin:auto;border:1px solid black;">TEST</div>
</body>
</html>
margin:0 auto;
works in IE8 if you have a Doctype that triggers standards mode.
If you don't have one, you should. If you really don't want one then you can hack around it.
margin: 0 auto;
works in all browsers (even as far as IE6).
You are either
- not specifying a
width
property so your container is actually centered it's just covering 100% of the width, or - have messed up the selector, try a property like
color
or debug with firebug - are triggering quirks mode because you are not specifying a doctype
- have a lot of errors in your markup; try validating your markup and fixing bad markup — so browsers don't have to guess (and possibly interpret your markup differently)
I found a not-so-good workaround for this
http://www.bluerobot.com/web/css/center1.html
If someone knows a better solution, please mention it here.
It works in IE8 but you have to notice IE8 that its a good idea to visualize your webpage with the IE8 standard mode... :S by this tag in the header:
<meta http-equiv="x-ua-compatible" content="IE=8"/>
精彩评论