makes nav-pills collapsable just like nav-bar in bootstrap

后端 未结 6 895
执念已碎
执念已碎 2020-12-08 05:33

we are developing an application and we are using twiiter bootstrap 3 we have created a navigation bar with nav-pills

   
6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-08 06:04

    First, you need to include HTML for the menu button once your menu collapses.

    
    

    Then, you need to wrap your nav-pills in a div containing Bootstrap's collapse class.

    
    

    You can then wrap all of this in a fluid-container and Bootstrap's navbar navbar-default with role=navigation.

    Additionally, you could add a bit of jQuery to handle "stacking" your menu when it is collapsed instead of remaining horizontal. To do this, Bootstrap's events for show/hide collapse will do the trick: show.bs.collapse and hide.bs.collapse.

    //Stack menu when collapsed
    $('#bs-example-navbar-collapse-1').on('show.bs.collapse', function() {
        $('.nav-pills').addClass('nav-stacked');
    });
    
    //Unstack menu when not collapsed
    $('#bs-example-navbar-collapse-1').on('hide.bs.collapse', function() {
        $('.nav-pills').removeClass('nav-stacked');
    });
    

    Working Demo Here

提交回复
热议问题