I’m using the latest version of Bootstrap to style a site and I have come across what seems like a bug. You can view it here as a JSFiddle.
If I add a standard fixed-position top navbar and then some content after it, the subsequent content gets pulled up by about 60px so it ends up under the top navbar. So I looked at the Bootstrap examples pages and found a bit of inline CSS (in the head section) that is evidently being used to correct this:
body {
padding-top: 60px; /* 60px to make the container go all the way to the bottom of the topbar */
}
This surprised me a great deal and I’m wondering if this is the result of an overlooked-bug in Bootstrap or if I should be doing this as a matter of course.
If the latter is the case, I’d be very interested to know why I should use inline CSS when Bootstrap is supposed to be a ready-to-go CSS solution.
And if the former, I’d very much like to know why this is as it is – why doesn’t the Bootstrap CSS just add the padding to the bottom of the navbar or something?
From the documentation:
The
.navbar-fixed-topisposition: fixed, so apaddingwill not affect any other element.EDIT
The “between the two .css” advice helps to prevent an issue with mobile devices. As
position: fixedis broken on many devices, navbar goesstaticand the<body>padding creates a blank wrap on the top. Sobootstrap-responsive.cssoverwrites this padding for that viewports.You can reproduce that behaviour simply by adding a media query to the rule:
Include this rule on your custom stylesheet and forget
<style>tags.