Bootstrap 3 - show collapsed navigation for all screen sizes

后端 未结 6 669
攒了一身酷
攒了一身酷 2020-12-01 02:14

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

相关标签:
6条回答
  • 2020-12-01 02:33

    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

    0 讨论(0)
  • 2020-12-01 02:39

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

    0 讨论(0)
  • 2020-12-01 02:40

    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.

    0 讨论(0)
  • 2020-12-01 02:46

    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.

    0 讨论(0)
  • 2020-12-01 02:46

    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;
    }
    
    0 讨论(0)
  • 2020-12-01 02:47

    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;
    }
    
    0 讨论(0)
提交回复
热议问题