Darren Wainwright
Darren Wainwright

Reputation: 30727

Bootstrap 3 - show collapsed navigation for all screen sizes

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?

Upvotes: 36

Views: 80467

Answers (6)

Carol Skelly
Carol Skelly

Reputation: 362290

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

Upvotes: 40

Sajidur Rahman
Sajidur Rahman

Reputation: 3060

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;
}

Upvotes: 2

wilcocammeraat
wilcocammeraat

Reputation: 61

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.

Upvotes: 2

Raju Gurung
Raju Gurung

Reputation: 11

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

Upvotes: 1

user5093523
user5093523

Reputation: 71

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;
}

Upvotes: 7

TheAllSeeingI
TheAllSeeingI

Reputation: 171

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.

Upvotes: 10

Related Questions