开发者

Why doesn't this html/css work in ie?

开发者 https://www.devze.com 2023-01-02 13:10 出处:网络
I am just trying to center a div on the page.It works in chrome but in i.e. the div is still on the left:

I am just trying to center a div on the page. It works in chrome but in i.e. the div is still on the left:

开发者_Go百科
<html>
<head></head>
<body>
  <div id="container" style="margin:0 auto; width:200px;">
       test
  </div>
</body>
</html>

Everything I've read has said that to center a block element, simply add margin:0 auto and specify a width, so I don't know why this isn't working.

I am testing on IE 7.0.5730


Your HTML snippet does not have a DOCTYPE, so IE is defaulting to quirksmode.

Using the HTML5 doctype:

<!DOCTYPE HTML>
<html>
<head></head>
<body>
  <div id="container" style="margin:0 auto; width:200px;">
       test
  </div>
</body>
</html>


another method would be to do this in your css, this way it works no matter if ie is in quirksmode or not:

body{text-align:center;}
#container{text-align: left;}
0

精彩评论

暂无评论...
验证码 换一张
取 消