4

Using Bootstrap Responsive Framework I have to use two Nav bars in my page. they work fine but in a toggle mode clicking on icon lists both "nav-collapce" items!

I tried to rename the collapse class name for second class but it didn't work. Can you please let me know how I can run both "nav-collapse collapse two times without any conflict?

<div class="navbar">
<div class="navbar-inner">
    <div class="container">
        <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        </a>
        <a class="brand" href="#">Candete</a>
        <div class="nav-collapse collapse">
            <!-- .nav, .navbar-search, .navbar-form, etc -->
            <ul class="nav">
                <li class="active"><a href="#">Home</a></li>
                <li><a href="#">Products</a></li>
                <li><a href="#">Contact Us</a></li>
                <li><a href="#">About Us</a></li>
                <li><a href="#">All Products</a></li>
            </ul>
        </div>
    </div>
</div>
</div>

<div class="navbar">
<div class="navbar-inner">
    <div class="container">
        <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        </a>
        <a class="brand" href="#">Product Category</a>
        <div class="nav-collapse collapse">
            <!-- .nav, .navbar-search, .navbar-form, etc -->
            <ul class="nav">
                <li><a href="#">Gold</a></li>
                <li><a href="#">Copper</a></li>
                <li><a href="#">Zinc</a></li>
                <li><a href="#">Metals</a></li>
                <li><a href="#">Other</a></li>
            </ul>
        </div>
    </div>
</div>

madth3
  • 7,275
  • 12
  • 50
  • 74
Behrouz Hosseini K.
  • 135
  • 1
  • 3
  • 14

2 Answers2

7

In Twitter Bootstrap, .nav-collapse is important class, so don't change it. What is best solution?

On line <div class="nav-collapse collapse"> add some new class, let's call it .menu1. So new code will be <div class="nav-collapse collapse menu1">. And then data-target=".nav-collapse" change to data-target=".menu1".

You can do the same thing with second menu and with some new .menu2 class, or leave it as it is (it will work, because both menus have different data-target).

And here is working demo http://jsfiddle.net/xmLDd/

Miljan Puzović
  • 5,840
  • 1
  • 24
  • 30
0

Give the nav-collapse elements unique IDs and target them with the IDs:

<div class="navbar">
  <div class="navbar-inner">
    <div class="container">
      <a class="btn btn-navbar" data-toggle="collapse" data-target="#nav-primary">
        ...
      </a>
      <div class="nav-collapse collapse" id="nav-primary">
        ...
      </div>
    </div>
  </div>
</div>

<div class="navbar">
  <div class="navbar-inner">
    <div class="container">
      <a class="btn btn-navbar" data-toggle="collapse" data-target="#nav-secondary">
        ...
      </a>
      ...
      <div class="nav-collapse collapse" id="nav-secondary">
        ...
      </div>
    </div>
</div>
Ross Allen
  • 43,772
  • 14
  • 97
  • 95
  • 1
    What's with the downvote? This is the same as the accepted answer but uses an ID instead of a one-off class (which is effectively an ID). – Ross Allen Jan 10 '14 at 16:33
  • Sorry I did not do this on purpose. Must have clicked the arrow by accident - edit your answer and I'll remove the downvote. – doque Jan 15 '14 at 14:42
  • Missing an end-quote on `id="nav-primary>` - I tried to edit it for you, but SO won't let me make a single-character edit. :( – snipe Oct 02 '14 at 19:35
  • Hi how do I differentiate two navbar-collapse in one navbar instead? I have named different data-targets, but that is not working still... – Krys Mar 22 '18 at 03:35
  • @Krys Can you create a new question? That sounds like something new to ask. – Ross Allen Mar 22 '18 at 12:07
  • @RossAllen I certainly will. I have fixed it and it works! I will post it very soon. – Krys Mar 22 '18 at 14:57