我有一个下拉菜单,如果我将鼠标放在上面,它会展开,当鼠标离开菜单时,它会缩回(即它可以工作)。问题是,当菜单扩展到另一个div时,我将光标移到另一个div上(当菜单打开,并与另一个div重叠时),菜单消失。如何禁用divs菜单销毁功能?
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>
答案 0 :(得分:1)
导航的父级的z-index
为2。
<div id="Tuotekategoriat" style="position: absolute; width: 862px; height: 60px; z-index: 2; left: 172px; top: 25px">
导航下的内容的z-index
为4.
<div id="layer21" style="position: absolute; width: 800px; height: 100px; z-index: 4; left: 185px; top: 160px"> test </div>
话虽如此,导航下的内容将始终显示在导航的顶部。您可以删除z-index
值,也可以使导航的值z-index
更高。
jsFiddle example - 将导航设置为z-index
5。
答案 1 :(得分:0)
从菜单下方的div中删除position: absolute
属性会阻止它被销毁。
请参阅小提琴:http://jsfiddle.net/9rULx/