Rather hard to describe the problem. So just look at this jsFiddle:
When the navbar gets fixed to the top the content jumps below it.
CSS:
.affix {
position: fixed;
top: 0px;
}
#above-top {
height: 100px;
background: black;
}
Where is the problem?
My solution, inspired by @niaccurshi's:
Instead of hard-coding a padding-top, create an invisible duplicate element that takes up the same amount of space, but only while the original element is affixed.
JS:
CSS:
The problem here is that there is no way communicated to the rest of the content in the container below the nav that the nav bar has been fixed to the top. You can achieve this using more modern CSS, but be aware that this won't be a fix for older browsers (and indeed there are issues you may find with postion:fixed properties in older browsers too...
This waits until the nav bar is fixed, and then adds padding to the container that is it's sibling, keeping it from "jumping" under the nav.
An alternative, if you want to avoid duplicate content.
You can also use Bootstrap affix events to add and remove padding (or margin) from the relevant element via CSS classes:
Here's a JSFiddle: http://jsfiddle.net/mumcmujg/1/