具有 height 属性 100% 的 html 元素不会覆盖整个窗口

标签 html css footer

我想在我的页面底部有一个页脚。 我遵循了很多不同的教程,但它不起作用。 当我缩放屏幕直到出现滚动条时,页脚位于窗口底部而不是页面末尾。

这是我的CSS:

 html {
    height: 100%;
    box-sizing: border-box;
}
*,
*:before,
*:after {
    box-sizing: inherit;
}
body{
    position: relative;
    font-size: 10px;
    font-family: Arial, Helvetica, sans-serif;
    min-height: 100%;
    padding-bottom: 40px;
    margin: 0;
}
#footer{
    position: absolute;
    bottom: 0;
    right: 0;
    left: 0;
    margin-left: 16%;
    margin-right: 16%;
    font-size: 11px;
    margin-top: 20px;
    margin-bottom: 15px;
    width: 68%;
}

html结构:

<!DOCTYPE html>
<html lang="nl">
    <body>
          <nav>
                ....
          </nav>
          <div id="content">
                ....
          </div>
          <div id="footer">
                ....
          </div>
    </body>
</html>

图片:

the footer at the bottem of the window

when I scroll down

有没有人可以帮助我?

提前致谢!

最佳答案

肯定还有其他原因,因为您的代码在该示例中运行良好。你在使用 iframe 吗?请尝试放一段代码

此外,如果您有一个带有 float 的元素 定位你应该放一个<div style='clear:both >`在#footer div 之前,如果您不清楚, float 元素可能会做很多奇怪的事情。

html {
    height: 100%;
    box-sizing: border-box;
}
*,
*:before,
*:after {
    box-sizing: inherit;
}
body{
    position: relative;
    font-size: 10px;
    font-family: Arial, Helvetica, sans-serif;
    min-height: 100%;
    padding-bottom: 40px;
    margin: 0;
}
#footer{
    position: absolute;
    bottom: 0;
    right: 0;
    left: 0;
    margin-left: 16%;
    margin-right: 16%;
    font-size: 11px;
    margin-top: 20px;
    margin-bottom: 15px;
    width: 68%;
}
<html>
  <body>
    <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
    <div id="footer"> footer</div>
    </body>
  </html>

关于具有 height 属性 100% 的 html 元素不会覆盖整个窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40156763/

相关文章:

html - 页脚没有出现在页面底部

c# - 从 C# 中的 .docx 文件的页眉和页脚获取图像

html - 如何控制 flexbox 中每列的元素数?

javascript - 使用带自动完成功能的 YUI 布局

html - bootstrap中md和xs的关系和依赖

html - 如何从导航菜单(小工具下方的+)下删除内容背景

javascript - CSS 不适用于动态创建的文本字段

css - 这个页脚留在 Chrome 中,我怎样才能让它在 Firefox 中保持不变

javascript - 将一个元素的 ID 值更改为另一个元素的数据属性

javascript - 如何使这个 div 可滚动?