36

I am using Bootstrap v3.

I have the navbar classes in place so that when I have my screen mobile-size the navigation collapses and the little grid-like toggle button appears - so this is working as expected.

what i would like, is for this to be the default action for all screen sizes. That is, even on a desktop I would like the navigation to be collapsed and the toggle button to be visible.

I've had a look through the css and there is a whole bunch of stuff that provides the functionality, though I don't know which parts to change.

I've tried commenting out the larger media-queries, though there are a lot of them and it seems to have a knock-on effect to other styling.

any ideas?

3
  • Can you post a link to the website? Commented Feb 18, 2014 at 16:53
  • Nope, sorry, internal site. Though if you see the standard bootstrap nav-bar - that's whats being used. Just need to have the nav-bar collapsed for all media sizes Commented Feb 18, 2014 at 16:55
  • 3
    This may be helpful: stackoverflow.com/questions/18192082/… Commented Feb 18, 2014 at 17:00

6 Answers 6

40

You can use override the default Bootstrap CSS like this...

    .navbar-header {
        float: none;
    }
    .navbar-toggle {
        display: block;
    }
    .navbar-collapse {
        border-top: 1px solid transparent;
        box-shadow: inset 0 1px 0 rgba(255,255,255,0.1);
    }
    .navbar-collapse.collapse {
        display: none!important;
    }
    .navbar-nav {
        float: none!important;
        margin: 7.5px -15px;
    }
    .navbar-nav>li {
        float: none;
    }
    .navbar-nav>li>a {
        padding-top: 10px;
        padding-bottom: 10px;
    }

Demo: http://www.bootply.com/114896

This will ensure that the collapsed navbar is always used by overriding the Bootstrap @media queries.

Update: For Bootstrap 4, you just need to remove the navbar-toggleable class: http://www.codeply.com/go/LN6szcJO53

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks - that did it for me. I get a weird thick grey bar at the bottom of the nav while its animating, though i'm sure i can figure that part.
this works well for bootstrap 3.0.3. After moving to 3.3.2 it needed this added to the css: .navbar-collapse.collapse.in {display: block !important; } . Otherwise when expanded, it would immed collapse.
@puddleglum where did you use that css though? You need display:none to initially hide the .navbar-collapse.collapse
@Rich - starting with skelly's answer above I just added it at the end and kept it all in a separate css file.
9

This is what worked for me.

Visit : http://getbootstrap.com/customize/

Locate : 'Less variables' --> 'Media queries breakpoints'

Change : @screen-lg value from 1200px to 1920px

Locate : "Grid system" --> @grid-float-breakpoint

Change : @screen-sm-min to @screen-lg

Scroll to end of page.

Click on "Compile and Download"

Extract and use these downloaded files.

1 Comment

This fix is a bit wild.
7

This worked for me:

.navbar-collapse.collapse {
    display: none!important;
}

If suppose you find problems with toggle too, then put the following:

.navbar-collapse.collapse.in{
    display: block!important;
}

Comments

2

Easiest way i found is to change the variable.less file and change

// Navbar collapse
//** Point at which the navbar becomes uncollapsed.
@grid-float-breakpoint:     @screen-sm-min;

to

// Navbar collapse
//** Point at which the navbar becomes uncollapsed.
@grid-float-breakpoint:     ( your break point );

Only if you use LESS ofc.

1 Comment

With the grid-float-breakpoint at 100%, it NEVER collapses. This is the opposite of what they wanted.
2

Wanted to save time but it wasn't perfect. I got some issues with latest bootstrap, there is some unnecessary code and has a overflow problem in the drop-down menu. This code was the best solution for me:

.navbar-header {
    float: none;
}
.navbar-toggle {
    display: block;
}
.navbar-collapse.collapse {
    display: none!important;
}
.navbar-collapse.collapse.in {
    display: block!important;
}
.navbar-nav {
    float: none!important;
}
.navbar-nav>li {
    float: none;
}

Comments

1

Adding 100% value on @grid-float-breakpoint (Grid system -> @grid-float-breakpoint -> 100% instead of @screen-sm-min).

1 Comment

Might want to add some explanation

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.