Two navbars collapsed into 1 for mobile?

2019-09-02 07:13发布

问题:

I have two menus in Bootstrap 3 - a Social Menu and a Main Menu. When collapsed on mobile, I get two menu open/toggle buttons to open the corresponding menu items.

Is there any way when collapsed, I can move the Social Menu Items into the Main Menu and use just one toggle/menu button and list? Code is Below...

<div id="social-menu" class="navbar navbar-default navbar-static-top" role="navigation">
   <div class="container">
      <div class="navbar-header">
         <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-social">
         <span class="sr-only">Toggle navigation</span>
         <span class="icon-bar"></span>
         <span class="icon-bar"></span>
         <span class="icon-bar"></span>
         </button>
      </div>
      <div class="collapse navbar-collapse navbar-menubuilder">
         <ul class="nav navbar-nav navbar-social">
            <li>Social Menu Item 1</li>
            <li>Social Menu Item 2</li>
            <li>Social Menu Item 3</li>
            <li>Social Menu Item 4</li>
         </ul>
      </div>
   </div>
</div>


<div id="main-menu" class="navbar navbar-default navbar-static-top" role="navigation">
   <div class="container">
      <div class="navbar-header">
         <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-main-menu">
         <span class="sr-only">Toggle navigation</span>
         <span class="icon-bar"></span>
         <span class="icon-bar"></span>
         <span class="icon-bar"></span>
         </button>
      </div>
      <div class="collapse navbar-collapse navbar-menubuilder">
         <ul class="nav navbar-nav navbar-main-menu">
            <li>Main Menu Item 1</li>
            <li>Main Menu Item 2</li>
            <li>Main Menu Item 3</li>
            <li>Main Menu Item 4</li>
         </ul>
      </div>
   </div>
</div>

Using Bootstrap 3

回答1:

Copy the 2nd nav bar into the same list as the main nav bar. Then add classes to the main nav bar to hide them on large desktops.

<div id="main-menu" class="navbar navbar-default navbar-static-top" role="navigation">
   <div class="container">
      <div class="navbar-header">
         <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-main-menu">
         <span class="sr-only">Toggle navigation</span>
         <span class="icon-bar"></span>
         <span class="icon-bar"></span>
         <span class="icon-bar"></span>
         </button>
      </div>
      <div class="collapse navbar-collapse navbar-menubuilder">
         <ul class="nav navbar-nav navbar-social">
            <li>Main Menu Item 1</li>
            <li>Main Menu Item 2</li>
            <li>Main Menu Item 3</li>
            <li>Main Menu Item 4</li>
            <li class="hidden-md hidden-lg">Social Menu Item 1</li>
            <li class="hidden-md hidden-lg">Social Menu Item 2</li>
            <li class="hidden-md hidden-lg">Social Menu Item 3</li>
            <li class="hidden-md hidden-lg">Social Menu Item 4</li>
         </ul>
      </div>
   </div>
</div>