您好我想在我的顶部导航栏中添加一个下拉菜单。 但由于某种原因,它被我的图像滑块隐藏。 我希望下拉内容能够覆盖所有内容。
/* Style The Dropdown Button */
.dropbtn {
cursor: pointer;
}
/* The container <div> - needed to position the dropdown content */
.dropdown {
position: relative;
display: inline-block;
z-index: 999;
}
/* Dropdown Content (Hidden by Default) */
.dropdown-content {
display: none;
position: absolute;
background-color: #565656;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
}
/* Links inside the dropdown */
.dropdown-content a {
color: white;
padding: 12px 16px;
text-decoration: none;
display: block;
}
/* Change color of dropdown links on hover */
.dropdown-content a:hover {
background-color: #f1f1f1
}
/* Show the dropdown menu on hover */
.dropdown:hover .dropdown-content {
display: block;
}
<div id="header">
<ul>
<li>
<a class="a-no-hover" href="index.html">
<img src="images/miniLogo.png" />
</a>
</li>
<li><a class="active" href="index.html">HOME</a>
</li>
<div class="dropdown">
<li class="dropbtn"><a href="product.html">PRODUCTS</a>
</li>
<div class="dropdown-content">
<a href="#">Link 1</a>
<a href="#">Link 2</a>
<a href="#">Link 3</a>
</div>
</div>
<li><a href="order.php">ORDER</a>
</li>
<li><a href="about.html">ABOUT US</a>
</li>
<li><a href="contact.html">CONTACT US</a>
</li>
</ul>
</div>
<div id="section1">
<img id="img" src="images/bg.jpg" />
</div>
答案 0 :(得分:2)
您正在向标题菜单提供z-index
,这很好。但内容是什么问题。因此,请尝试将z-index
提供给.dropdown-content
:
/* Dropdown Content (Hidden by Default) */
.dropdown-content {
display: none;
position: absolute;
background-color: #565656;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1000; /* One more than the header. */
}
<强>更新强>
#header ul {
list-style-type: none;
margin: 0;
padding: 0;
/* overflow: hidden; Remove this. */
text-align: center;
vertical-align: middle;
}
预览强>