Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make Scrolling NavBar Stick At Top Of Browser In Bootstrap

I'm new to Twitter Bootstrap and want to have a NavBar at the bottom of a deep'ish MastHead and when the user vertically scrolls the page and the NavBar gets to the top of the page, change the style to so that the NavBar becomes Fixed. The effect I want is the same as http://www.happycog.com/ only using the Bootstrap NavBar.

So, the real question is how to trigger the navbar-fixed-top style when the NavBar is scrolled to position 0 ie: the top of the browser.

Any ideas or pointers would be appreciated. Thank you.

like image 561
user1493194 Avatar asked Jun 30 '12 15:06

user1493194


People also ask

How do I make my navbar stick to the top when I scroll?

To create a sticky navbar, you use the position: fixed; CSS property to "stick" your navbar to the viewport, and position: sticky; to make it stick to its parent element.

How do I make the navbar appear on top?

To create a fixed top menu, use position:fixed and top:0 . Note that the fixed menu will overlay your other content. To fix this, add a margin-top (to the content) that is equal or larger than the height of your menu.

How do I make my Bootstrap header sticky?

How does Sticky Header work in Bootstrap? Sticky Header is nothing but navigation bar, if we want to make navigation bar becomes stick at the top (sticky header) then use offsetTop within the JavaScript file. Include bootstrap feature in our application we must specify some pre-defined libraries inside our application.


1 Answers

The CSS class navbar-fixed-top is what you want to add.

Here's an example:

<nav class='navbar navbar-inverse navbar-fixed-top sticky' role='navigation'>
    <!-- nav content -->
</nav>
like image 142
Evert Arnould Avatar answered Oct 12 '22 22:10

Evert Arnould