html - Css 悬停菜单显示在 div 后面

标签 html css

我制作了一个 css 悬停菜单。问题是菜单的内容(下拉内容)显示在菜单下方的井后面。如何让内容显示在“井”div 类的前面。谢谢。

HTML

  <div class = "dropdown">
   <button class = "dropbtn">
   <b>HOME</b></button>
  <div class ="dropdown-content">
    <a href ="#">About Us</a>
    <a href ="#">What we Do</a>
    <a href ="#">Services</a>
    <a href ="#">Leadership</a>
  </div>
  </div>
  <div class = "dropdown">
   <button class = "dropbtn">
   <b>WHO WE ARE</b></button>
   <div class ="dropdown-content">
     <a href ="#">C#</a>
     <a href ="#">Javascript</a>
     <a href ="#">HTML</a>
     <a href ="#">Python</a>
   </div>
  </div>

 <div class = "dropdown">
  <button class = "dropbtn">
  <b>CCTP</b></button>
  <div class ="dropdown-content">
    <a href ="#">Brian M</a>
    <a href ="#">Qata S</a>
    <a href ="#">Nyonyozi J</a>
    <a href ="#">Frank K</a>
  </div>
 </div>

CSS

.dropbtn{
background-color: #2c3e50;
color:white;
padding: 16px;
font-size: 13px;
font-family: arial;
border:none;
cursor:pointer;
border-radius: 7px;
border:3px solid #D67C1C;
height: 43px;

}
/*container needed to position the dropdown content*/
.dropdown{
 position: relative;
 display:inline-block;
 background-color: #2c3e50;
}
/*Dropdown content(hidden by default)*/
.dropdown-content{

  display: none;
  border-radius: 7px;
  font-weight: 400;
  font-style: bold;
  position: absolute;
  background-color: #2c3e50;
  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 links on hover*/
.dropdown-content a:hover{
  background-color: #D67C1C;
}
 /*show the dropdown menu on hover*/
.dropdown:hover
.dropdown-content{
  display: block;
}
 /*change the background colorof dropdown-button when dropdown content is shown*/
.dropdown:hover
.dropbtn{
  background-color: #D67C1C;

}

很好

<div class = "well">
        <div class = "panel-body">

          <h4>Welcome to Mobile Ltd</h4>
          <p>Lorem ipsum dolaor sit amet,consecteur adisping elit.morbi gravida quam ante rutrum,in mollis ligula mattis.Integer mulla nissi,ellamcorper et posuere.Lorem ipsum dolaor sit amet,consecteur adisping elit.morbi gravida quam ante rutrum,in mollis ligula mattis.Integer mulla nissi,ellamcorper et posuere.Lorem ipsum dolaor sit amet,consecteur adisping elit.morbi gravida quam ante rutrum,in mollis ligula mattis.Integer mulla nissi,ellamcorper et posuere.Lorem ipsum dolaor sit amet,consecteur adisping elit.morbi gravida quam ante rutrum,in mollis ligula mattis.Integer mulla nissi,ellamcorper et posuere.Lorem ipsum dolaor sit amet,consecteur adisping elit.morbi gravida quam ante rutrum,in mollis ligula mattis.Integer mulla nissi,ellamcorper et posuere.Lorem ipsum dolaor sit amet,consecteur adisping elit.morbi gravida quam ante rutrum,in mollis ligula mattis.Integer mulla nissi,ellamcorper et posuere</p> 
 </div>

最佳答案

您需要将 z-index 属性添加到 .dropdown-content CSS。

.dropdown-content{
    ... other styles ...
    z-index: 2;
 }

关于html - Css 悬停菜单显示在 div 后面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39583668/

相关文章:

html/css 图像不会在浏览器调整大小时展开父元素

javascript - 多个小型 DOM 操作与一个大型 DOM 操作

javascript - 如何检查加载时输入是否为空?

css - 如何将 html 布局分成三列,其中 div 可以跨越多个 1/3 宽度?

html - 在 HTML 表格的每一行上交替使用 CSS 类

c# - Silverlight 而非 WPF 中嵌套样式(如 CSS)的挂件

html - 隐藏输入时 Bootstrap 填充间隙

html - CSS - 定位难题

html - 跨浏览器显示

css - 使用 IE 11 在 <td> 中填充导致渲染问题