2

我有一个下拉菜单,如果我将鼠标放在其中,它会展开,当鼠标离开菜单时,它会缩回(即它可以工作)。问题是,当菜单在另一个 div 上展开时,我将光标移到另一个 div 上(当菜单打开并与另一个 div 重叠时),菜单就会消失。如何禁用 div 菜单破坏功能?

CSS:

  nav ul ul {
  display: none;

   z-index: 888;
}


nav ul li:hover > ul {
  display: block;
  z-index: 888;
}


nav ul {
background: #efefef; 
background: linear-gradient(top, #efefef 0%, #bbbbbb 100%);  
background: -moz-linear-gradient(top, #efefef 0%, #bbbbbb 100%); 
background: -webkit-linear-gradient(top, #efefef 0%,#bbbbbb 100%); 
box-shadow: 0px 0px 9px rgba(0,0,0,0.15);
padding: 0 20px;
border-radius: 10px;  
list-style: none;
position: relative;
display: inline-table;
z-index: 888;
}


nav ul:after {
  content: ""; clear: both; display: block;
  z-index: 888;
}


nav ul li {
  float: left;
  z-index: 888;
}


nav ul li:hover {
  background: #4b545f;
  background: linear-gradient(top, #4f5964 0%, #5f6975 40%);
  background: -moz-linear-gradient(top, #4f5964 0%, #5f6975 40%);
  background: -webkit-linear-gradient(top, #4f5964 0%,#5f6975 40%);
  z-index: 888;
}
  nav ul li:hover a {
      color: #fff;
      z-index: 888;
  }


nav ul li a {
  display: block; padding: 25px 40px;
  color: #757575; text-decoration: none;
  z-index: 888;
}


nav ul ul {
  background: #5f6975; border-radius: 0px; padding: 0;
  position: absolute; top: 100%;
  z-index: 888;
}


nav ul ul li {
  float: none; 
  border-top: 1px solid #6b727c;
  border-bottom: 1px solid #575f6a;
  position: relative;
  z-index: 888;
}


nav ul ul li a {
  padding: 15px 40px;
  color: #fff;
  z-index: 888;
} 


nav ul ul li a:hover {
  background: #4b545f;
  z-index: 888;
}

nav ul ul ul {
  position: absolute; left: 100%; top:0;
  z-index: 888;
}

相对 HTML:

Headers and stuff here before this:

<div id="Tuotekategoriat" style="position: absolute; width: 862px; height: 60px; z-index: 2; left: 172px; top: 25px"> <nav>   <ul>
  <li><a>Ratsastajalle</a>            <ul>
              <li><a href="products.php?category=Housut">Housut</a></li>
              <li><a href="products.php?category=Takit">Takit</a></li>
              <li><a href="products.php?category=Hanskat">Hanskat</a></li>
              <li><a href="Kypärät">Kypärät</a></li>
              <li><a href="products.php?category=Raipat">Raipat</a></li>
              <li><a href="products.php?category=Saappaat">Saappaat</a></li>          </ul>       </li>       <li><a>Hevoselle</a>            <ul>
              <li><a href="products.php?category=Satulat">Satulat</a></li>
              <li><a href="products.php?category=Satulatarvikkeet">Satulatarvikkeet</a></li>
              <li><a href="products.php?category=Suitset">Suitset</a></li>
              <li><a href="products.php?category=Loimet">Loimet</a></li>
              <li><a href="products.php?category=Rintaremmit">Rintaremmit</a></li>            </ul>
  </li>       <li><a>Hoitotuotteet</a>            <ul>            </ul>       </li>
  <li><a>Rehut ja lisäravinteet</a>           </li>
              <li><a>Yritys</a>               <ul>
              <li><a href="#">Yhteystiedot</a></li>
              <li><a href="#">Ehdot</a></li>          </ul>       </li>

  </ul> </nav>

</div>

and another div here:

<div id="layer21"  style="position: absolute; width: 800px; height: 100px; z-index: 4; left: 185px; top: 160px"> test </div>
4

2 回答 2

1

导航的父级的 az-index为 2。

<div id="Tuotekategoriat" style="position: absolute; width: 862px; height: 60px; z-index: 2; left: 172px; top: 25px">

导航下的内容有一个z-index4。

<div id="layer21" style="position: absolute; width: 800px; height: 100px; z-index: 4; left: 185px; top: 160px"> test </div>

话虽如此,导航下的内容将始终显示在导航的顶部。您可以删除这些z-index值,或者使导航具有更高的z-index值..

jsFiddle 示例- 将导航设置z-index为 5。

于 2013-11-05T23:22:12.790 回答
0

从菜单下方的 div 中删除position: absolute属性会阻止它被破坏。

见小提琴:http: //jsfiddle.net/9rULx/

于 2013-11-05T23:22:05.643 回答