过去一小时我一直试图弄清楚我的粘性页脚无法正常工作的问题。我有与getboostrap网站上给出的示例完全相同的结构,但它似乎不起作用。什么是错误的想法?
正确加载了所有引导程序css文件。
<body style="">
<div id="wrap">
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/">Application name</a>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li><a href="/">Home</a></li>
<li><a href="/Home/About">About</a></li>
<li><a href="/Home/Contact">Contact</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="/Account/Register" id="registerLink">Register</a></li>
<li><a href="/Account/Login" id="loginLink">Log in</a></li>
</ul>
</div>
</div>
</div>
<div class="container">
<div class="jumbotron">
<h1>ASP.NET</h1>
<p class="lead">ASP.NET is a free web framework for building great Web sites and Web applications using HTML, CSS and JavaScript.</p>
<p><a href="http://asp.net" class="btn btn-primary btn-large">Learn more »</a></p>
</div>
<div class="row">
<div class="col-md-4">
<h2>Getting started</h2>
<p>
ASP.NET MVC gives you a powerful, patterns-based way to build dynamic websites that
enables a clean separation of concerns and gives you full control over markup
for enjoyable, agile development.
</p>
<p><a class="btn btn-default" href="http://go.microsoft.com/fwlink/?LinkId=301865">Learn more »</a></p>
</div>
<div class="col-md-4">
<h2>Get more libraries</h2>
<p>NuGet is a free Visual Studio extension that makes it easy to add, remove, and update libraries and tools in Visual Studio projects.</p>
<p><a class="btn btn-default" href="http://go.microsoft.com/fwlink/?LinkId=301866">Learn more »</a></p>
</div>
<div class="col-md-4">
<h2>Web Hosting</h2>
<p>You can easily find a web hosting company that offers the right mix of features and price for your applications.</p>
<p><a class="btn btn-default" href="http://go.microsoft.com/fwlink/?LinkId=301867">Learn more »</a></p>
</div>
</div>
</div>
</div>
<div id="footer">
<div class="container">
<p class="text-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>
我找到了解决方案。我认为包括所有CSS也会有页脚的CSS,但显然它没有。您需要以下内容才能使粘性页脚与引导程序一起使用
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 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;
}
答案 0 :(得分:12)
你为什么不使用:
.navbar-fixed-bottom
这将解决您的底部固定导航问题,您可以在其中放置任何内容。
答案 1 :(得分:7)
快速解决您的代码并对页脚进行一些调整:http://jsfiddle.net/2Zaxt/。
<div id="footer" class="container">
<nav class="navbar navbar-default navbar-fixed-bottom">
<div class="navbar-inner navbar-content-center">
<p class="text-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>
</nav>
</div>
答案 2 :(得分:6)
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 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;
}
答案 3 :(得分:1)
这就是我的工作方式。
我将页脚ID和自定义样式值添加到该ID,并为相同的外观添加了“navbar-default”
<强> HTML 强>
<div id="footer" class="navbar-default">
<div class="container">
<p>Your Footer Content Here</p>
</div>
</div>
<强> CSS 强>
#footer {
background-color: #F5F5F5;
bottom: 0;
height: 60px;
position: relative;
width: 100%;
}
答案 4 :(得分:1)
您可以在bootstrap文档中找到“带固定导航栏的粘性页脚”(固定在页面顶部)的示例:http://getbootstrap.com/examples/sticky-footer-navbar/
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;
}
/* Fixed navbar styles */
body > .container {
padding-top: 60px;
}
答案 5 :(得分:1)
基于@ teh0wner的粘性页脚的简单独特解决方案,我添加了一些JS
<强> CSS 强>
html {
position: relative;
min-height: 100%;
}
footer {
position: absolute;
bottom: 0;
width: 100%;
}
<强> JS 强>
$(document).ready(function() {
var height = $('footer').height();
$('body').css({
"margin-bottom": height
});
});
答案 6 :(得分:0)
在bootstrap 3中,容器和页脚类以某种方式覆盖你的css规则。我试图改变我的页脚的背景颜色。我尝试了许多我在网上找到的解决方案并且无法成功完成的事情。在使用了针对页脚的clearfix类后,页面成为了我真正想要看到的内容。
.myFooter {
background-color: #c4a9f1;
width: 100%;
}
.hi-icon a {
display: block;
width: 100%;
height: 100%;
position: absolute;
top: 0px;
z-index: 100;
}
<footer class="footer clearfix">
<div class="container myFooter">
<div class=" ">
<div class="col-sm-3">
<h3 class="page-header">Part 1 </h3>
<ul>
<li>Link1</li>
<li>Link2</li>
<li>Link3</li>
<li>Link4</li>
</ul>
</div>
<div class="col-sm-3">
<h3 class="page-header">Part 2</h3>
<ul>
<li>Link1</li>
<li>Link2</li>
<li>Link3</li>
<li>Link4</li>
</ul>
</div>
</div>
</div>
</div>
</footer>