Bra*_*her 201 html css twitter-bootstrap twitter-bootstrap-3
我一直在使用twitter bootstrap框架已经有一段时间了,他们最近更新到版本3!
我无法将粘性页脚粘到底部,我使用了twitter bootstrap网站提供的入门模板,但仍然没有运气,有什么想法吗?
Jon*_*Jon 188
只需将navbar-fixed-bottom类添加到页脚即可.
<div class="footer navbar-fixed-bottom">
Run Code Online (Sandbox Code Playgroud)
tky*_*mtk 151
参考官方Boostrap3粘性页脚示例,无需添加<div id="push"></div>,CSS更简单.
官方例子中使用的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;
/* Negative indent footer by its height */
margin: 0 auto -60px;
/* Pad bottom by footer height */
padding: 0 0 60px;
}
/* Set the fixed height of the footer here */
#footer {
height: 60px;
background-color: #f5f5f5;
}
Run Code Online (Sandbox Code Playgroud)
和基本的HTML:
<body>
<!-- Wrap all page content here -->
<div id="wrap">
<!-- Begin page content -->
<div class="container">
</div>
</div>
<div id="footer">
<div class="container">
</div>
</div>
</body>
Run Code Online (Sandbox Code Playgroud)
你可以在sticky-footer exmaple的源代码中找到这个css的链接.
<!-- Custom styles for this template -->
<link href="sticky-footer.css" rel="stylesheet">
Run Code Online (Sandbox Code Playgroud)
完整网址:http: //getbootstrap.com/examples/sticky-footer/sticky-footer.css
ana*_*ocs 52
这是一个方法,它将添加一个粘性页脚,除了Bootstrap中的内容之外不需要任何其他CSS或Javascript,并且不会干扰您当前的页脚.
只需将其直接复制并粘贴到您的代码中即可.没有大惊小怪.
<div class="navbar navbar-default navbar-fixed-bottom">
<div class="container">
<p class="navbar-text pull-left">© 2014 - Site Built By Mr. M.
<a href="http://tinyurl.com/tbvalid" target="_blank" >HTML 5 Validation</a>
</p>
<a href="http://youtu.be/zJahlKPCL9g" class="navbar-btn btn-danger btn pull-right">
<span class="glyphicon glyphicon-star"></span> Subscribe on YouTube</a>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
Dav*_*roa 34
除了刚添加的CSS之外,请记住在关闭wrap div之前需要添加push div
HTML的基本结构是
<div id="wrap">
page content here
<div id="push"></div>
</div> <!-- end wrap -->
<div id="footer">
footer content here
</div> <!-- end footer -->
Run Code Online (Sandbox Code Playgroud)
Len*_*rri 28
这是今天的Sticky Footer简化代码,因为它们总是在优化它,这很好:
HTML
<!DOCTYPE html>
<html lang="en">
<head></head>
<body>
<!-- Fixed navbar -->
<div class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Project name</a>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#about">About</a></li>
<li><a href="#contact">Contact</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li class="divider"></li>
<li class="dropdown-header">Nav header</li>
<li><a href="#">Separated link</a></li>
<li><a href="#">One more separated link</a></li>
</ul>
</li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
<!-- Begin page content -->
<div class="container">
<div class="page-header">
<h1>Sticky footer with fixed navbar</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. A fixed navbar has been added with <code>padding-top: 60px;</code> on the <code>body > .container</code>.</p>
<p>Back to <a href="../sticky-footer">the default sticky footer</a> minus the navbar.</p>
</div>
<footer>
<div class="container">
<p class="text-muted">Place sticky footer content here.</p>
</div>
</footer>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
CSS
/* Sticky footer styles
-------------------------------------------------- */
html {
position: relative;
min-height: 100%;
}
body {
/* Margin bottom by footer height */
margin-bottom: 60px;
}
footer {
position: absolute;
bottom: 0;
width: 100%;
/* Set the fixed height of the footer here */
height: 60px;
background-color: #f5f5f5;
}
Run Code Online (Sandbox Code Playgroud)
iMi*_*Mil 28
我在这个问题上有点晚了,但是我遇到了这个帖子,因为我刚被这个问题所困扰,终于找到了一个非常简单的方法来克服它,只需使用启用navbar了navbar-fixed-bottom类的方法.例如:
<div class="navbar navbar-default navbar-fixed-bottom">
<div class="container">
<span class="navbar-text">
Something useful
</span>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
HTH
zee*_*zee 10
这是我对此问题的更新解决方案.
/* Sticky footer styles
-------------------------------------------------- */
html {
position: relative;
min-height: 100%;
}
body {
/* Margin bottom by footer height */
margin-bottom: 60px;
}
.footer {
position: absolute;
bottom: 0;
width: 100%;
/* Set the fixed height of the footer here */
height: 60px;
background-color: #f5f5f5;
border-top: 1px solid #eee;
text-align: center;
}
.site-footer-links {
font-size: 12px;
line-height: 1.5;
color: #777;
padding-top: 20px;
display: block;
text-align: center;
float: center;
margin: 0;
list-style: none;
}
Run Code Online (Sandbox Code Playgroud)
并像这样使用它:
<div class="footer">
<div class="site-footer">
<ul class="site-footer-links">
<li>© Zee and Company<span></span></li>
</ul>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
要么
html, body {
height: 100%;
}
.page-wrap {
min-height: 100%;
/* equal to footer height */
margin-bottom: -142px;
}
.page-wrap:after {
content: "";
display: block;
}
.site-footer, .page-wrap:after {
height: 142px;
}
.site-footer {
background: orange;
}
Run Code Online (Sandbox Code Playgroud)
这个粘性的例子对我不起作用。我的解决方案:
#footer {
position: fixed;
bottom: 0;
width: 100%;
height: 3em;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
327023 次 |
| 最近记录: |