gpt4 book ai didi

html - 第二个 Bootstrap 导航栏与第一个导航栏的下拉菜单重叠?

转载 作者:行者123 更新时间:2023-12-05 02:14:52 24 4
gpt4 key购买 nike

我有两个固定顶部导航栏,第一个导航栏的下拉菜单被第二个导航栏重叠。尝试弄乱 z-index、定位和溢出。还发现了一些相关的问题,但似乎没有任何帮助。任何想法可能是什么原因造成的?

链接到 FIDDLE

下图显示了问题的本质(第二个导航栏重叠下拉菜单):

enter image description here

例子:

<!DOCTYPE html>
<html>
<head>
<meta>
<title>Navbar overlapping dropdown-menu</title>

<!-- Bootstrap 4 cdn's & jquery dependency -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>

</head>
<body>

<!-- first navbar with dropdown-menu -->
<nav class="navbar bg-dark fixed-top navbar-expand-sm">
<div class="collapse navbar-collapse">
<ul class="navbar-nav">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown"> Dropdown </a>
<div class="dropdown-menu">
<a class="dropdown-item" href="#"> 1 </a>
<a class="dropdown-item" href="#"> 2 </a>
<a class="dropdown-item" href="#"> 3 </a>
<a class="dropdown-item" href="#"> 4 </a>
</div>
</li>
</ul>
</div>
</nav>


<!-- second navbar with top offset -->
<nav class="navbar bg-primary fixed-top navbar-expand-sm" style="top:56px!important;">
<p>hello world</p>
</nav>

</body>
</html>

最佳答案

你是对的,这是一个 z-index 问题。尝试添加一些样式来降低第二个 navbar 的 z-index。当弄乱 z-index 时,请记住调整导致问题的 sibling 。调整 .dropdown-menu 没有任何作用,因为问题出在父元素上。

你可以这样做:

.navbar {
z-index: 90;
}

.navbar+.navbar {
z-index: 80;
top:56px;
}
<!DOCTYPE html>
<html>

<head>
<meta>
<title>Navbar overlapping dropdown-menu</title>

<!-- Bootstrap 4 cdn's & jquery dependency -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>

</head>

<body>

<!-- first navbar with dropdown-menu -->
<nav class="navbar bg-dark fixed-top navbar-expand-sm">
<div class="collapse navbar-collapse">
<ul class="navbar-nav">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown"> Dropdown </a>
<div class="dropdown-menu">
<a class="dropdown-item" href="#"> 1 </a>
<a class="dropdown-item" href="#"> 2 </a>
<a class="dropdown-item" href="#"> 3 </a>
<a class="dropdown-item" href="#"> 4 </a>
</div>
</li>
</ul>
</div>
</nav>


<!-- second navbar with top offset -->
<nav class="navbar bg-primary fixed-top navbar-expand-sm">
<p>hello world</p>
</nav>

</body>

</html>

关于html - 第二个 Bootstrap 导航栏与第一个导航栏的下拉菜单重叠?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52999666/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com