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

标签 html css

所以我得到了一个导航栏,当你将鼠标悬停在它们上面时,其中的一些元素有一个下拉菜单。在导航栏的正下方,有一个图像幻灯片。问题是每次我将鼠标悬停在下拉菜单上时,幻灯片 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/

相关文章:

javascript - 将 3X3 变换矩阵转换为 4X4 矩阵,用于 css transform matrix3d

html - Bootstrap 'col' 标签不会将文章拉入尽可能多的行

html - 导航栏和液体设计

javascript - 如何使 html div 在其高度达到页面的 100% 高度后垂直滚动?

html - 在 bootstrap 主题中添加向右拉按钮

html - 我无法让我的 CSS 代码正常工作

javascript - 如何附加到 HTML 范围元素的当前位置

html - 如何根据内容强制容器扩展高度

javascript - IE : Removing readonly doesn't work until clicked

javascript - 使用 flexbox 垂直对齐内容