【发布时间】:2011-03-24 17:24:41
【问题描述】:
我想知道为什么在我放入文档类型之前,以下 HTML/CSS 呈现良好:
<body style="margin:0; padding:0; background-color:#eeeeee"></body>
<div id="HeaderContainer" style="background-color:#eeeeee; color:Black; border-bottom:1px solid #cccccc; height:60px; margin:0px"></div>
<div style="width:100%; background-color:White; margin:0px; padding:0px">
<div style="margin:30px; width:840px; margin:10px auto; margin-top:50px; background-color:#cc0000;">
text
</div>
</div>
</div>
</body>
我想要的是底部带有深灰色边框的标题(灰色条)。在此之下,我想要我的内容,它进入一个 100% 宽度的大 div,它是白色的(因为页面是灰色的)。上面的代码看起来不错,但是如果我将这一行添加到顶部:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
最里面的div的边距从白色变成灰色,所以页面看起来不对。
谁能解释为什么?我正在使用 IE8 进行测试,但在 Chrome 中看起来是一样的。
图片说明:
【问题讨论】:
-
你的第一个 div 已经关闭,然后里面多了一个。