这是我的 html5 标记
<div id="header">
</div>
<div id="content">
</div>
<div id="footer">
</div>
现在用css
header {
height: 95px;
position: fixed;
width: 100%;
min-width: 980px;
}
footer {
background: #000000;
bottom: 0;
height: 30px;
position: fixed;
width: 100%;
min-width: 980px
}
现在我的问题是当我将任何内容放入其中时
<div id="content">
</div>
内容来自 top:0,这不是必需的。我不想在内容上使用填充或边距。有什么方法可以使内容位于标题下方。
原文由 Soarabh 发布,翻译遵循 CC BY-SA 4.0 许可协议
主要原因是因为
<header>
是position:fixed
将其从文档流中取出。您需要添加margin
<body>
- 或padding
<content>
此外,如果使用 HTML5 元素,请将其添加到 CSS 规则的顶部以与旧版浏览器兼容。取自 Eric Meyer 的 CSS Reset 。