html - 我怎样才能强制我的页脚贴在 CSS 中任何页面的底部?

标签 html css footer sticky-footer

这是我的代码:

#footer {
   font-size: 10px;
   position:absolute;
   bottom:0;
   background:#ffffff;
}

我不知道这有什么问题 - 谁能帮忙?

编辑:为了更清楚地说明问题所在:页脚在页面加载时按预期显示在底部。但是,当网页的高度大于屏幕上的尺寸以致出现滚动条时,页脚将保留在同一位置。也就是说,当页面高度 <= 100% 时,页脚在底部。但是,当页面高度 >100% 时,页脚不在该页面的底部,而是在可见屏幕的底部。

编辑:令人惊讶的是,以下解决方案均无效。我最终实现了侧边栏。

最佳答案

您可能正在寻找 this example :

<div class="wrapper">
    Your content here
    <div class="push"></div>
</div>
<div class="footer">
    Your footer here
</div>

CSS:

对于 142 像素的页脚

html, body {
    height: 100%;
}
.wrapper {
    min-height: 100%;
    height: auto !important;
    height: 100%;
    margin: 0 auto -142px; /* the bottom margin is the negative value of the footer's height */
}
.footer, .push {
    height: 142px; /* .push must be the same height as .footer */
}

/*

Sticky Footer by Ryan Fait
http://ryanfait.com/

*/

关于html - 我怎样才能强制我的页脚贴在 CSS 中任何页面的底部?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5516910/

相关文章:

html - li > 填充未填充父 li div

html - SVG 图像未在任何版本的 IE 中显示

css - 在 Firefox 中,表格边距不会折叠

html - 不适合 1 行的 3 个 div

ios - Pixate 支持 -webkit-border-image css 属性吗?

php - HTML 电子邮件仅显示为代码

html - 页脚重叠动态生成的表格

html - 我如何让页脚粘在底部

html - 页脚随屏幕变大而移动

javascript - 无法通过 JavaScript 调用淡入淡出 div