Cal*_*eng 291 css footer twitter-bootstrap
我通常熟悉使用CSS刷新页脚的技巧.
但是我在使用这种方法为Twitter引导工作时遇到了一些麻烦,很可能是因为Twitter引导本质上是响应式的.使用Twitter bootstrap我无法使用上面博客文章中描述的方法让页脚刷新到页面底部.
san*_*non 454
这现在包含在Bootstrap 2.2.1中.
Bootstrap 3.x
使用navbar组件并添加.navbar-fixed-bottom类:
<div class="navbar navbar-fixed-bottom"></div>
Run Code Online (Sandbox Code Playgroud)
Bootstrap 4.x
<div class="navbar fixed-bottom"></div>
Run Code Online (Sandbox Code Playgroud)
不要忘记添加body { padding-bottom: 70px; }或以其他方式覆盖页面内容.
文档:http://getbootstrap.com/components/#navbar-fixed-bottom
小智 314
发现这里的片段非常适合bootstrap
HTML:
<div id="wrap">
<div id="main" class="container clear-top">
<p>Your content here</p>
</div>
</div>
<footer class="footer"></footer>
Run Code Online (Sandbox Code Playgroud)
CSS:
html, body {
height: 100%;
}
#wrap {
min-height: 100%;
}
#main {
overflow:auto;
padding-bottom:150px; /* this needs to be bigger than footer height*/
}
.footer {
position: relative;
margin-top: -150px; /* negative value of footer height */
height: 150px;
clear:both;
padding-top:20px;
}
Run Code Online (Sandbox Code Playgroud)
Hen*_*ryW 74
Twitter bootstrap的一个工作示例NOT STICKY FOOTER
<script>
$(document).ready(function() {
var docHeight = $(window).height();
var footerHeight = $('#footer').height();
var footerTop = $('#footer').position().top + footerHeight;
if (footerTop < docHeight)
$('#footer').css('margin-top', 10+ (docHeight - footerTop) + 'px');
});
</script>
Run Code Online (Sandbox Code Playgroud)
#footer如果内容适合屏幕而不想要滚动条,只需将10的值更改为0
如果内容不适合屏幕,则会显示滚动条.
Len*_*rri 34
以下是从官方页面实现此操作的方法:
http://getbootstrap.com/2.3.2/examples/sticky-footer.html
我刚刚测试了它,它工作得很棒!:)
HTML
<body>
<!-- Part 1: Wrap all page content here -->
<div id="wrap">
<!-- Begin page content -->
<div class="container">
<div class="page-header">
<h1>Sticky footer</h1>
</div>
<p class="lead">Pin a fixed-height footer to the bottom of the viewport in desktop browsers with this custom HTML and CSS.</p>
</div>
<div id="push"></div>
</div>
<div id="footer">
<div class="container">
<p class="muted credit">Example courtesy <a href="http://martinbean.co.uk">Martin Bean</a> and <a href="http://ryanfait.com/sticky-footer/">Ryan Fait</a>.</p>
</div>
</div>
</body>
Run Code Online (Sandbox Code Playgroud)
相关的CSS代码是这样的:
/* Sticky footer styles
-------------------------------------------------- */
html,
body {
height: 100%;
/* The html and body elements cannot have any padding or margin. */
}
/* Wrapper for page content to push down footer */
#wrap {
min-height: 100%;
height: auto !important;
height: 100%;
/* Negative indent footer by it's height */
margin: 0 auto -30px;
}
/* Set the fixed height of the footer here */
#push,
#footer {
height: 30px;
}
#footer {
background-color: #f5f5f5;
}
/* Lastly, apply responsive CSS fixes as necessary */
@media (max-width: 767px) {
#footer {
margin-left: -20px;
margin-right: -20px;
padding-left: 20px;
padding-right: 20px;
}
}
Run Code Online (Sandbox Code Playgroud)
san*_*eep 33
对于Sticky Footer,我们DIV's在HTML中使用两个用于基本粘性页脚效果.像这样写:
HTML
<div class="container"></div>
<div class="footer"></div>
Run Code Online (Sandbox Code Playgroud)
CSS
body,html {
height:100%;
}
.container {
min-height:100%;
}
.footer {
height:40px;
margin-top:-40px;
}
Run Code Online (Sandbox Code Playgroud)
use*_*ser 29
更简单的官方示例:http://getbootstrap.com/examples/sticky-footer-navbar/
html {
position: relative;
min-height: 100%;
}
body {
margin-bottom: 60px;
}
.footer {
position: absolute;
bottom: 0;
width: 100%;
height: 60px;
background-color: #f5f5f5;
}
Run Code Online (Sandbox Code Playgroud)
Ras*_*him 27
<div class="min-vh-100 d-flex flex-column
justify-content-between">
<div> <!-- Wrapper (Without footer) -->
<header>
I am a header.
</header>
<article>
I am an article!
</article>
</div> <!-- End: Wrapper (Without footer) -->
<footer>
I am a footer.
</footer>
</div>
Run Code Online (Sandbox Code Playgroud)
确保<div>使用以下 Bootstrap 类将所有内容包装在 a 或任何其他块级元素中:min-vh-100, d-flex,flex-column,justify-content-between 。
确保将除页脚元素之外的所有内容都包装在 a<div>或任何其他块级元素中。
确保您使用<footer>或任何其他块级元素来包裹页脚。
min-vh-100确保 body 元素至少拉伸到屏幕的整个高度
flex-column在保留堆叠块元素方面保持正常文档流的行为(假设正文的直接子元素确实都是块元素)。
justify-content-between将页脚推到屏幕底部。
查看如何仅使用 CSS 执行相同操作(将页脚保持在底部) -链接
小智 23
使用 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>
Run Code Online (Sandbox Code Playgroud)
.d-flex 使主 div 成为一个 flex 容器.flex-column 在主 div 上将您的弹性项目排列在一列中min-height: 100vh 到主 div,使用样式属性或在您的 CSS 中,以垂直填充视口.flex-grow-1 在容器上,使主内容容器占据视口高度中剩余的所有空间的元素。Max*_*tin 18
好吧,我发现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>
Run Code Online (Sandbox Code Playgroud)
它似乎很好,适合我

参见中的示例 Fiddle
Moh*_*OUI 14
在最新版本的bootstrap 4-alpha中,我能够使用.fixed-bottom类来完成它.
<div class="fixed-bottom"></div>
Run Code Online (Sandbox Code Playgroud)
这是我如何使用它与页脚:
<footer class="footer fixed-bottom container">
<hr>
<p>© 2017 Company, Inc.</p>
</footer>
Run Code Online (Sandbox Code Playgroud)
您可以在此处的展示位置文档中找到更多信息.
Cor*_*ory 12
HenryW的答案很好,但我需要做一些调整才能让它按照我想要的方式工作.特别是以下处理:
这些调整对我有用:
HTML:
<div id="footer" class="invisible">My sweet footer</div>
Run Code Online (Sandbox Code Playgroud)
CSS:
#footer {
padding-bottom: 30px;
}
Run Code Online (Sandbox Code Playgroud)
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;
});
Run Code Online (Sandbox Code Playgroud)
sp_*_*mer 11
这对我很有用.
将此类navbar-fixed-bottom添加到页脚.
<div class="footer navbar-fixed-bottom">
Run Code Online (Sandbox Code Playgroud)
我用它是这样的:
<div class="container-fluid footer navbar-fixed-bottom">
<!-- start footer -->
</div>
Run Code Online (Sandbox Code Playgroud)
并且它在整个宽度上设置为底部.
编辑:这将设置页脚始终可见,这是您需要考虑的事项.
And*_*ich 10
你需要包装你的.container-fluiddiv以便你的粘性页脚工作,你也错过了你.wrapper班上的一些属性.试试这个:
padding-top:70px从您的body代码中删除并将其包含在您的代码中.container-fluid,如下所示:
.wrapper > .container-fluid {
padding-top: 70px;
}
Run Code Online (Sandbox Code Playgroud)
我们必须这样做,因为body向下推动以容纳导航栏最终将页脚推进到视口之后(70px更远),因此我们得到一个滚动条.我们得到更好的结果推动.container-fluiddiv.
接下来我们必须删除div .wrapper之外的类.container-fluid并#main用它包装div,如下所示:
<div class="wrapper">
<div id="main" class="container-fluid">
<div class="row-fluid">...</div>
<div class="push"></div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
你的页脚当然必须不在.wrapperdiv中,所以将它从`.wrapper div中删除并将其放在外面,如下所示:
<div class="wrapper">
....
</div>
<footer class="container-fluid">
....
</footer><!--END .row-fluid-->
Run Code Online (Sandbox Code Playgroud)
完成所有操作后,.wrapper使用负边距正确地将您的页脚推向您的班级,如下所示:
.wrapper {
min-height: 100%;
height: auto !important; /* ie7 fix */
height: 100%;
margin: 0 auto -43px;
}
Run Code Online (Sandbox Code Playgroud)
这应该有用,虽然你可能需要修改一些其他的东西,以便在调整屏幕大小时使其工作,比如重置.wrapper类的高度,如下所示:
@media (max-width:480px) {
.wrapper {
height:auto;
}
}
Run Code Online (Sandbox Code Playgroud)
这是使用Twitter Bootstrap和新的navbar-fixed-bottom类的正确方法:(你不知道我花了多长时间寻找这个)
CSS:
html {
position: relative;
min-height: 100%;
}
#content {
padding-bottom: 50px;
}
#footer .navbar{
position: absolute;
}
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
Here's a solution that doesn't require rethinking the HTML structure or any additional CSS trickery involving padding:
<html style="height:100%;">
...
<body class="d-flex flex-column h-100">
...
<main class="flex-grow-1">...</main>
<footer>...</footer>
</body>
...
</html>
Run Code Online (Sandbox Code Playgroud)
Note that this solution allows for footers with flexible heights, which particularly comes in handy when designing pages for multiple screen sizes with content wrapping when shrunk.
style="height:100%;" makes the <html> tag take the whole space of the document.d-flex sets display:flex to our <body> tag.flex-column sets flex-direction:column to our <body> tag. Its children (<header>, <main>, <footer> and any other direct child) are now aligned vertically.h-100 sets height:100% to our <body> tag, meaning it will cover the entire screen vertically.flex-grow-1 sets flex-grow:1 to our <main>, effectively instructing it to fill any remaining vertical space, thus amounting to the 100% vertical height we set before on our <body> tag.Working demo here: https://codepen.io/maxencemaire/pen/VwvyRQB
See https://css-tricks.com/snippets/css/a-guide-to-flexbox/ for more information on flexbox.
| 归档时间: |
|
| 查看次数: |
541912 次 |
| 最近记录: |