Bootstrap two navbars collapsing

Bootstrap two navbars collapsing

In bootstrap i want to have two navbars below eachother.
My idea:
Navbar 1 has a brand: main menu.
Navbar 2 (below navbar1) has a brand called: sub menu.
When the user looks at the site on his mobile phone he/she sees two collapsible navbars.
The user can now choose wich navbar to open. The menu or the sub menu.
I just copied the standard code on the bootstrap website: http://getbootstrap.com/components/#navbar
Strange thing is. When i make my browser small. Two collapsed navbars appear. “Main-menu” and “sub-menu”. When i click on the butten behind main menu the main menu appears. Just like it should. But when i press the sub-menu (uncollapse) button. The MAIN-MENU opens again. Not the sub menu.
I just used the standard navbar code from the bootstrap website in the link pasted those beneath eachoter and changed the brand names.
HERE is the bootply: http://bootply.com/101690
Test it on mobile and see what happens in the navbars.

Related:  HTML code inside buttons with simple_form

Solutions/Answers:

Solution 1:

You use the same id value for both navbar, change the id for the second navbar and the corresponding data-target value:

 <nav class="navbar navbar-default" role="navigation">
  <!-- Brand and toggle get grouped for better mobile display -->
  <div class="navbar-header">
    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
      <span class="sr-only">Toggle navigation</span>
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
    </button>
    <a class="navbar-brand" href="#">MAIN menu</a>
  </div>

  <!-- Collect the nav links, forms, and other content for toggling -->
  <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
    <ul class="nav navbar-nav">
      <li class="active"><a href="#">MAIN menu link1</a></li>

    </ul>
  </div><!-- /.navbar-collapse -->
</nav>
<nav class="navbar navbar-default" role="navigation">
  <!-- Brand and toggle get grouped for better mobile display -->
  <div class="navbar-header">
    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-2">
      <span class="sr-only">Toggle navigation</span>
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
    </button>
    <a class="navbar-brand" href="#">Sub menu</a>
  </div>

  <!-- Collect the nav links, forms, and other content for toggling -->
  <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-2">
    <ul class="nav navbar-nav">
      <li class="active"><a href="#">Sub menu link1</a></li>

    </ul>
  </div><!-- /.navbar-collapse -->
</nav>

Working example

Related:  AngularJS passing data to bootstrap modal

References