位置固定内容重叠问题

新手上路,请多包涵

这是我的 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 许可协议

阅读 613
2 个回答

主要原因是因为 <header>position:fixed 将其从文档流中取出。您需要添加 margin <body> - 或 padding <content> 此外,如果使用 HTML5 元素,请将其添加到 CSS 规则的顶部以与旧版浏览器兼容。

 /* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
    display: block;
}

取自 Eric Meyer 的 CSS Reset

原文由 Marcel 发布,翻译遵循 CC BY-SA 2.5 许可协议

最佳解决方案使用:

 position: sticky;
top: 0;

原文由 Vijay Tailor 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
logo
Stack Overflow 翻译
子站问答
访问
宣传栏