3

In bootstrap 3, I want the navbar to be collapsed by default for all screen sizes.

I have found here that Bootstrap 3 being mobile first, its navbar is "collapsed" by default and and "expands" when it reaches a certain minimum size.. Following that post, I tried messing around with @grid-float-breakpoint for customized css, but I got nowhere. Please guide me from here.

Community
  • 1
  • 1
sutro
  • 623
  • 6
  • 13

1 Answers1

12

You could use CSS to override the Bootstrap 3 defaults. For example, this would set the navbar to collapse on screen widths less than 2000 pixels (accommodating most screens)..

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

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


Update for Bootstrap 4 (beta)

In Bootstrap 4 the navbar is always collapsed into the mobile/hamburger version by default: Demo. The navbar-expand-* class are used to change the breakpoint.

Carol Skelly
  • 351,302
  • 90
  • 710
  • 624
  • yours is working fine however, it's occupying the whole width. do you know how to set the width when you expand? and it should be on the right side only – iPhoneJavaDev Mar 06 '16 at 15:01
  • I don't understand your comment. You'd change the 2000 accordingly to toggle the horizontal menu/collapsed menu – Carol Skelly Mar 06 '16 at 21:12