css - 为什么这个 html/css 在 ie 中不起作用?

标签 css internet-explorer html

我只是想在页面上居中放置一个 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 代码段没有 DOCTYPEso 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/

相关文章:

html - 在 FireFox 中格式化好,在 IE 中格式化不好....帮助

javascript - IE 11 错误 - 图像在标签内的表单内 - 需要保留鼠标事件

html - CSS left, position 和 floating ...在多个浏览器中的不同结果

css - 特定于打印的 javascript

javascript - 添加新 div 时 jQuery 事件失败

html - 覆盖预定义的 CSS 样式

internet-explorer - 在 Internet Explorer 中启用 SOCKS 4a/5

html - 将字体图标附加到文本字符串中的最后一个单词并防止换行

html - 当某些行有表情符号而某些行没有表情符号时,如何使表中的行垂直对齐?

javascript - 使用 Bootstrap 轮播 slider 的高度困难