简体   繁体   English

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

[英]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. 我正在使用bootstrap 3构建一个网页,我遇到了多个固定导航栏的问题。 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. 我尝试将下拉列表的z-index设置为更高的值但是,它不起作用。

Fiddler : https://jsfiddle.net/99x50s2s/152/ 提琴手https//jsfiddle.net/99x50s2s/152/

在此输入图像描述

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. 任何建议表示赞赏。

Can you change the order of the elements in the DOM ? 你能改变DOM中元素的顺序吗? If so, just put .navbar-fixed-top2 before .navbar-fixed-top . 如果是这样,只是把.navbar-fixed-top2.navbar-fixed-top

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

Try something like the following fiddle: 尝试以下小提琴:

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

I've added some CSS: 我添加了一些CSS:

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

and ID to the actionLinks 和动作链接的ID

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

You can make enclose both navbars so they are fixed and you have some HTML that should be adjusted See Docs . 您可以将两个导航栏括起来以便修复它们并且您有一些应该调整的HTML请参阅文档

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> 

I decreased the z-index of the bottom navbar to a negative value and it worked. 我将底部导航栏的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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM