gpt4 book ai didi

html - 如何使html中的下拉菜单与另一个div重叠

转载 作者:太空宇宙 更新时间:2023-11-03 20:32:00 26 4
gpt4 key购买 nike

所以我得到了一个导航栏,当你将鼠标悬停在它们上面时,其中的一些元素有一个下拉菜单。在导航栏的正下方,有一个图像幻灯片。问题是每次我将鼠标悬停在下拉菜单上时,幻灯片 div 都会挡路,因此无法看到下拉菜单。 enter image description here

我有ff html代码

  <div class="dropdown">
<li class="dropbtn">About Us</li>
<div class="dropdown-content">
<a href="#"> Overview and History</a>
<a href="#">Vision</a>
<a href="#">Objectives</a>
<a href="#">Organization</a>
<a href="#">About NEU</a>
</div>
</div>

和CSS

    .dropbtn {
background-color: inherit;
color: black;
padding: 12px;
font-size: 20px;
border: none;
cursor: pointer;
}

.dropdown {
position: relative;
display: inline-block;
margin: 0;
padding: 0px;
}

.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
}

.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}

.dropdown-content a:hover {background-color: #f1f1f1}

.dropdown:hover .dropdown-content {
display: block;
}

.dropdown:hover .dropbtn {
background-color: #0099ff;
}

最佳答案

您可以使用 z-index 属性,因为它指定了元素的堆叠顺序。

具有较高堆栈顺序的元素始终位于具有较低堆栈顺序的元素之前。

注意:z-index 仅适用于定位元素(position:absolute、position:relative 或 position:fixed)。

示例:

<!DOCTYPE html>
<html>
<head>
<style>
img {
position: absolute;
left: 0px;
top: 0px;
z-index: -1;
}
</style>
</head>
<body>

<h1>This is a heading</h1>

<img src="w3css.gif" width="100" height="140">

<p>Because the image has a z-index of -1, it will be placed behind the text.</p>

</body>
</html>

更多信息: Check out here

关于html - 如何使html中的下拉菜单与另一个div重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40059845/

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