Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 831
Darren Wainwright Avatar asked Feb 18 '14 16:02

Darren Wainwright


People also ask

How do I make my navigation bar collapsible?

To create a collapsible navigation bar, use a button with class="navbar-toggler", data-toggle="collapse" and data-target="#thetarget" . Then wrap the navbar content (links, etc) inside a div element with class="collapse navbar-collapse" , followed by an id that matches the data-target of the button: "thetarget".

How do I stop bootstrap 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 .

What is a toggler in bootstrap?

Bootstrap Toggle is a highly flexible Bootstrap plugin that converts checkboxes into toggles.


1 Answers

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

like image 60
Zim Avatar answered Oct 05 '22 19:10

Zim