固定页脚的 CSS

新手上路,请多包涵

我有一个非常基本的 HTML 页面。代码如下所示:

 <body>
  <header style="min-height: 255px;">
  </header>

  <article style="padding-bottom: 60px; width: 900px; margin: 0 auto;">
    Body text goes here.
  </article>

  <footer style="position: absolute; bottom: 0px; width: 100%; height: 60px; background-color: black;">
    Copyright information
  </footer>
</body>

通常,我的正文相当大。文本足够大,需要滚动条。看起来页脚位于文本的顶部,朝向底部。然后,当我向下滚动时,页脚不会保持固定。我究竟做错了什么?

谢谢

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

阅读 350
2 个回答

您需要 position:fixed; 在页脚中:

 <body>
  <header style="min-height: 255px;">
  </header>

  <article style="padding-bottom: 60px; width: 900px; margin: 0 auto;">
    Body text goes here.
  </article>

  <footer style="position: fixed; bottom: 0px; width: 100%; height: 60px; background-color: black;">
    Copyright information
  </footer>
</body>

原文由 Philipp Hofmann 发布,翻译遵循 CC BY-SA 3.0 许可协议

推荐问题
logo
Stack Overflow 翻译
子站问答
访问
宣传栏