I have this Twitter Bootstrap code
-
<div class='navbar' data-spy="affix" data-offset-top="0">
If your navbar is on the top of the page originally, set the value to 0. Otherwise, set the value for data-offset-top
to the value of the content above your navbar.
Meanwhile, you need to modify the css
as such:
.affix{
width:100%;
top:0;
z-index: 10;
}
讨论(0)
-
I am using jQuery to solve this problem. This is the snippet for BS 3.0.0:
$(window).resize(function () {
$('body').css('padding-top', parseInt($('#main-navbar').css("height"))+10);
});
$(window).load(function () {
$('body').css('padding-top', parseInt($('#main-navbar').css("height"))+10);
});
讨论(0)
-
In my project derived from the MVC 5 tutorial I found that changing the body padding had no effect. The following worked for me:
@media screen and (min-width:768px) and (max-width:991px) {
body {
margin-top:100px;
}
}
@media screen and (min-width:992px) and (max-width:1199px) {
body {
margin-top:50px;
}
}
It resolves the cases where the navbar folds into 2 or 3 lines. This can be inserted into bootstrap.css anywhere after the lines
body {
margin: 0;
}
讨论(0)
-
For bootstrap 3, the class navbar-static-top
instead of navbar-fixed-top
prevents this issue, unless you need the navbar to always be visible.
讨论(0)
-
Add to your CSS:
body {
padding-top: 65px;
}
From the Bootstrap docs:
The fixed navbar will overlay your other content, unless you add padding to the top of the body.
讨论(0)
-
a much more handy solution for your reference, it works perfect in all of my projects:
change your first 'div' from
<div class='navbar navbar-fixed-top'>
to
<div class="navbar navbar-default navbar-static-top">
讨论(0)