我只是想在页面上居中放置一个 div。它适用于 chrome 但在即 div 仍在左侧:
<html>
<head></head>
<body>
<div id="container" style="margin:0 auto; width:200px;">
test
</div>
</body>
</html>
我读过的所有内容都说要使 block 元素居中,只需添加 margin:0 auto
并指定宽度,所以我不知道为什么这不起作用。
我正在 IE 7.0.5730 上测试
最佳答案
您的 HTML 代码段没有 DOCTYPE
,so IE is defaulting to quirksmode .
使用 HTML5 文档类型:
<!DOCTYPE HTML>
<html>
<head></head>
<body>
<div id="container" style="margin:0 auto; width:200px;">
test
</div>
</body>
</html>
关于css - 为什么这个 html/css 在 ie 中不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2998629/