JGV
JGV

Reputation: 5187

Dropdown items are hidden by navbar in bootstrap

I am building a web page using bootstrap 3 and I am facing a problem with multiple fixed navbars. I have arranged the fixed navbars one after the another and the issue I am facing is, the dropdown in the first fixed navbar is not fully visible as the second fixed navbar is hiding it.

I tried setting the z-index of the dropdown to a higher value but, it did not work.

Fiddler: https://jsfiddle.net/99x50s2s/152/

enter image description here

Code:

<nav class="navbar navbar-default navbar-fixed-top">
  <div class="container-fluid">
      <img src="https://cdn4.iconfinder.com/data/icons/SUPERVISTA/animals/png/48/swallow_bird.png"></img>
    <ul class="nav navbar-nav pull-right">       
        <li class="dropdown">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Action Links <span class="caret"></span></a>
          <ul class="dropdown-menu">
            <li><a href="#">Action</a></li>
            <li><a href="#">Another action</a></li>
            <li><a href="#">Something else here</a></li>
            <li role="separator" class="divider"></li>
            <li><a href="#">Separated link</a></li>
          </ul>
        </li>
      </ul>
  </div>
</nav>
<nav class="navbar navbar-inverse navbar-fixed-top nav2">
  <div class="container-fluid">
      <p class="navbar-text">Instruction will appear here...</p>
  </div>
</nav>

Expectation:

The dropdown items should be visible above the second fixed navbar. Any suggestion is appreciated.

Upvotes: 1

Views: 1488

Answers (4)

vanburen
vanburen

Reputation: 21663

You can make enclose both navbars so they are fixed and you have some HTML that should be adjusted See Docs.

See example Snippet.

.navbar .navbar-brand {
  padding: 1px 5px;
  margin: 0;
  height: 30px;
}
.navbar.navbar-top {
  margin-bottom: 0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<nav class="navbar-fixed-top">
  <div class="navbar navbar-default navbar-static-top navbar-top">
    <div class="container-fluid">
      <div class="navbar-header">
        <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-nav" aria-expanded="false"> <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="#">
          <img src="https://cdn4.iconfinder.com/data/icons/SUPERVISTA/animals/png/48/swallow_bird.png"></img>
        </a>

      </div>
      <div class="collapse navbar-collapse" id="bs-nav">
        <ul class="nav navbar-nav navbar-right">
          <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Action Links <span class="caret"></span></a>

            <ul class="dropdown-menu">
              <li><a href="#">Action</a>

              </li>
              <li><a href="#">Another action</a>

              </li>
              <li><a href="#">Something else here</a>

              </li>
              <li role="separator" class="divider"></li>
              <li><a href="#">Separated link</a>

              </li>
            </ul>
          </li>
        </ul>
      </div>
    </div>
  </div>
  <div class="navbar navbar-inverse navbar-static-top">
    <div class="container-fluid">
      <p class="navbar-text">Instruction will appear here...</p>
    </div>
  </div>
</nav>

Upvotes: 1

Jorge Zuverza
Jorge Zuverza

Reputation: 915

Try something like the following fiddle:

https://jsfiddle.net/99x50s2s/155/

I've added some CSS:

#actionlinks{
  position:relative;
  z-index:50;
}
.nav2{
  position:relative;
  z-index:30;
}

and ID to the actionLinks

reference: http://sevenspark.com/diagnosis/z-index-submenu-hidden-behind-content

Upvotes: 2

Bug Hunter 219
Bug Hunter 219

Reputation: 344

I decreased the z-index of the bottom navbar to a negative value and it worked.

 <nav class="navbar navbar-inverse navbar-fixed-top nav2" style="z-index:-100;">
  <div class="container-fluid">
      <p class="navbar-text">Instruction will appear here...</p>
  </div>
</nav>

Upvotes: 0

long-lazuli
long-lazuli

Reputation: 414

Can you change the order of the elements in the DOM ? If so, just put .navbar-fixed-top2 before .navbar-fixed-top.

As in https://jsfiddle.net/99x50s2s/154/

Upvotes: 1

Related Questions