【发布时间】:2013-10-20 06:28:44
【问题描述】:
我正在尝试Bootstrap,但我想知道,如果滚动内容,如何修复底部的页脚而不使其从页面中消失?
【问题讨论】:
标签: html css twitter-bootstrap footer
我正在尝试Bootstrap,但我想知道,如果滚动内容,如何修复底部的页脚而不使其从页面中消失?
【问题讨论】:
标签: html css twitter-bootstrap footer
要获得一个贴在视口底部的页脚,请给它一个固定的位置,如下所示:
footer {
position: fixed;
height: 100px;
bottom: 0;
width: 100%;
}
Bootstrap 在 Navbar > Placement 部分中包含此 CSS,其类为 fixed-bottom。只需将此类添加到您的页脚元素:
<footer class="fixed-bottom">
引导文档:https://getbootstrap.com/docs/4.4/utilities/position/#fixed-bottom
【讨论】:
fixed-bottom 没有达到我的预期,我改为 static-bottom 以尊重页面内容高度。
添加这个:
<div class="footer navbar-fixed-bottom">
https://stackoverflow.com/a/21604189
编辑: 自 Bootstrap v4-alpha.6 起,navbar-fixed-bottom 类已更改为 fixed-bottom。
http://v4-alpha.getbootstrap.com/components/navbar/#placement
【讨论】:
添加fixed-bottom:
<div class="footer fixed-bottom">
【讨论】:
在此方法中添加z-index:-9999;,否则如果您有1,它将覆盖您的顶栏。
【讨论】:
另一种解决方案:
您可以使用“最小高度:80vh;”。
这允许您使用视口高度设置最小高度。
引导示例:
<style>
main {
min-height: 80vh;
height: auto !important;
height: 100%;
margin: 0 auto -60px;
}
</style>
<main class="container">
<!-- Your page content here... -->
</main>
<footer class="footer navbar-fixed-bottom">
<!-- Your page footer here... -->
</footer>
| Compatibility : |
|---|
| Chrome 31+ / FireFox 31+ / Safari 7+ / Internet Expl. 9+ / Opera 29+ |
【讨论】:
您可以通过将页面内容包装在 div 中并应用以下 id 样式来做到这一点:
<style>
#wrap {
min-height: 100%;
height: auto !important;
height: 100%;
margin: 0 auto -60px;
}
</style>
<div id="wrap">
<!-- Your page content here... -->
</div>
为我工作。
【讨论】:
【讨论】: