html - 固定页脚的 CSS

标签 html 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>

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

谢谢

最佳答案

你的页脚需要 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>

关于html - 固定页脚的 CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13788357/

相关文章:

html - 无法让 <span> 标签在超链接内工作

html - 删除表格单元格自动调整大小

html - 使用内联 CSS 更改按钮的背景颜色

css:将 div 元素放在另一个 div(底部)旁边的正确方法(如果它们不在一起)

css - 尝试使用隐藏属性对显示/隐藏定义列表进行动画处理(隐藏属性导致动画不起作用)

html - 当使用 bootstrap 4 和 AngularMaterial2 减小屏幕尺寸时,文本不对齐

javascript - 将两个按钮合并为一个切换按钮

html - 省略号(三个点)不会显示较长的文本

javascript - 如果选中/选中所有 2 维单选按钮,则启用按钮

jquery - 无法在我的 360 度 slider 上加载图像