下拉项目由导航栏中的导航栏隐藏

时间:2015-11-17 23:10:10

标签: jquery html css twitter-bootstrap

我正在使用bootstrap 3构建一个网页,我遇到了多个固定导航栏的问题。我已经一个接一个地安排固定的导航栏并且我面临的问题是,第一个固定导航栏中的下拉列表不完全可见,因为第二个固定导航栏正在隐藏它。

我尝试将下拉列表的z-index设置为更高的值但是,它不起作用。

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

enter image description here

代码:

<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>

期望:

下拉项目应显示在第二个固定导航栏上方。任何建议都表示赞赏。

4 个答案:

答案 0 :(得分:1)

您可以更改DOM中元素的顺序吗? 如果是这样,只需将.navbar-fixed-top2放在.navbar-fixed-top之前。

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

一样

答案 1 :(得分:1)

尝试以下小提琴:

http://docs.oracle.com/javase/7/docs/api/java/util/List.html

我添加了一些CSS:

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

和actionLinks的ID

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

答案 2 :(得分:1)

您可以将两个导航栏括起来以便修复它们并且您有一些应该调整的HTML请参阅Docs

请参阅示例代码段。

&#13;
&#13;
.navbar .navbar-brand {
  padding: 1px 5px;
  margin: 0;
  height: 30px;
}
.navbar.navbar-top {
  margin-bottom: 0;
}
&#13;
<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>
&#13;
&#13;
&#13;

答案 3 :(得分:0)

我将底部导航栏的z-index缩小为负值并且有效。

 <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>