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?

Darren Wainwright
  • 30,247
  • 21
  • 76
  • 127

6 Answers6

41

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

Carol Skelly
  • 351,302
  • 90
  • 710
  • 624
  • 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. – Darren Wainwright Feb 19 '14 at 23:30
  • 23
    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 Apr 23 '15 at 19:42
  • @puddleglum where did you use that css though? You need display:none to initially hide the .navbar-collapse.collapse – Rich Jan 11 '16 at 22:29
  • @Rich - starting with skelly's answer above I just added it at the end and kept it all in a separate css file. – puddleglum Jan 14 '16 at 22:20
10

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.

TheAllSeeingI
  • 171
  • 3
  • 10
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;
}
Aracthor
  • 5,757
  • 6
  • 31
  • 59
user5093523
  • 71
  • 1
  • 2
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.

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;
}
Sajidur Rahman
  • 2,764
  • 1
  • 27
  • 26
1

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

dakab
  • 5,379
  • 9
  • 43
  • 67