Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap 3 navbar-fixed-top stay fixed in mobile view

This may be a bug or just my bad coding. I've built a website using twitter bootstrap 2.3.* and found no problem, especially for the responsive function. The problem came up when I tried to switch into bootstrap 3.RC-2 which was latest stable release (according to Wikipedia). I have also tried with the examples contained in the download, and had the same result when I tried to resize the viewport.

Please have a look at http://bootply.com/69863 for the example, and try to resize window browser then click render view, and try to expand menu and scroll the page.

My real question is how do I make the fixed navbar static when in mobile (collapsible) view?

like image 832
gema Avatar asked Aug 16 '13 02:08

gema


People also ask

How do I keep my navbar fixed on top?

To create a fixed top menu, use position:fixed and top:0 .

How do I keep the navbar at the top of my viewport?

I found it necessary to add a z-index with a high enough number for the navbar to appear always on top of other elements.

How do I stop my navbar from collapsing?

For navbars that never collapse, add the .navbar-expand class on the navbar. For navbars that always collapse, don't add any .navbar-expand class.


2 Answers

Additionally to what Bass Jobsen has mentioned, for a better usability on mobile, the following CSS snippet removes the "sub-scrolling" on the navigation bar and removes the top margin which is there due to the large screen fixed navbar:

@media (max-width: 767px) {
    .navbar-fixed-top {
        position: relative;
        top: auto;
    }
    .navbar-collapse {
        max-height: none;
    }
    body {
        margin: 0;
    }
}
like image 22
DarkScrolls Avatar answered Sep 28 '22 14:09

DarkScrolls


.navbar-fixed-top keeps the navbar fixed top for all screen sizes now. This will be the default. When you take a look at navbar.less you will see no media queries are applied on this class too.

To make the navbar static after the collapse add the css shown below after the Boostrap CSS:

@media (max-width: 767px) /* @grid-float-breakpoint -1 */
{
    .navbar-fixed-top
    {
    position: relative;
    top: auto;
    }
}
like image 140
Bass Jobsen Avatar answered Sep 28 '22 15:09

Bass Jobsen