我通常熟悉使用css刷新页脚的技术。
但是我在将这种方法用于Twitter引导时遇到了一些麻烦,很可能是因为Twitter引导本质上是响应式的。使用Twitter引导,我不能得到页脚冲洗到页面底部使用上述博客文章中描述的方法。
我通常熟悉使用css刷新页脚的技术。
但是我在将这种方法用于Twitter引导时遇到了一些麻烦,很可能是因为Twitter引导本质上是响应式的。使用Twitter引导,我不能得到页脚冲洗到页面底部使用上述博客文章中描述的方法。
当前回答
这是用Twitter Bootstrap和新的navbar-fixed-bottom类的正确方法:(你不知道我花了多长时间寻找这个)
CSS:
html {
position: relative;
min-height: 100%;
}
#content {
padding-bottom: 50px;
}
#footer .navbar{
position: absolute;
}
HTML:
<html>
<body>
<div id="content">...</div>
<div id="footer">
<div class="navbar navbar-fixed-bottom">
<div class="navbar-inner">
<div class="container">
<ul class="nav">
<li><a href="#">Menu 1</a></li>
<li><a href="#">Menu 2</a></li>
</ul>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
其他回答
bootstrap是这样做的:
http://getbootstrap.com/2.3.2/examples/sticky-footer.html
只需使用页面源代码,您就应该能够看到。不要忘记<div id="wrap">在顶部。
这对我来说非常有效。
将这个类navbar-fixed-bottom添加到你的页脚。
<div class="footer navbar-fixed-bottom">
我是这样用的:
<div class="container-fluid footer navbar-fixed-bottom">
<!-- start footer -->
</div>
它在整个宽度的底部。
编辑:这将设置页脚始终可见,这是你需要考虑的事情。
HenryW的答案很好,尽管我需要做一些调整才能让它按我想要的方式工作。特别地,下面也处理:
避免“跳跃性”页面加载首先标记不可见和设置在javascript可见 优雅地处理浏览器大小调整 此外,如果浏览器变得更小,页脚变得比页面大,设置页脚备份 高度函数调整
以下是这些调整对我有效的方法:
HTML:
<div id="footer" class="invisible">My sweet footer</div>
CSS:
#footer {
padding-bottom: 30px;
}
JavaScript:
function setFooterStyle() {
var docHeight = $(window).height();
var footerHeight = $('#footer').outerHeight();
var footerTop = $('#footer').position().top + footerHeight;
if (footerTop < docHeight) {
$('#footer').css('margin-top', (docHeight - footerTop) + 'px');
} else {
$('#footer').css('margin-top', '');
}
$('#footer').removeClass('invisible');
}
$(document).ready(function() {
setFooterStyle();
window.onresize = setFooterStyle;
});
使用Bootstrap 4中内置的flex实用程序! 以下是我使用Bootstrap 4工具得到的结果。
<div class="d-flex flex-column" style="min-height: 100vh;">
<header></header>
<div class="container flex-grow-1">
<div>Some Content</div>
</div>
<footer></footer>
</div>
.d-flex使主div成为一个伸缩容器 .flex-column在主div来安排你的flex项目在一个列 min-height: 100vh到主div,可以使用style属性,也可以在CSS中,垂直填充视口 元素上的.flex-grow-1,让主内容容器占用视口高度中剩余的所有空间。
我找到了mix of navbar-inner和navbar-fixed-bottom
<div id="footer">
<div class="navbar navbar-inner navbar-fixed-bottom">
<p class="muted credit"><center>ver 1.0.1</center></p>
</div>
</div>
这看起来不错,而且对我很有效
参见小提琴中的例子