我有2个Divs,内部div有z-index:2,当鼠标在Div子菜单上方时显示,主div有z-index:1但是当我将鼠标移到子菜单上时内部div在主div下打开,我该怎么办? THX
<div id="Menu" style="top:0px;left:121px;width:170px;display:inline-block;;position:absolute;z-index:1;">
<div onmouseover="stayedIn=true;document.getElementById('SubMenu').style.display = 'inline-block';" onmouseleave="stayedIn=false;setTimeout(function(){if(stayedIn==false) {document.getElementById('SubMenu').style.display = 'none';}}, 300);" style="cursor:pointer;background-color:#10406e;height:20px;width:100%;color:white;border:1px solid #3994c1;padding-top:7px;padding-bottom:7px;display:inline-block;">
SubMenu
<div style="float:right;display:inline-block;margin-top:5px;margin-right:5px;"><img border="0" src="../../<?php if($_SERVER['HTTP_HOST']=='localhost') echo 'worldnewsmaster/';?>images/small_right_arrow.png"></div>
</div>
<div id="SubMenu" onmouseover="stayedIn=true;" onmouseleave="stayedIn=false;setTimeout(function(){if(stayedIn==false) {document.getElementById('SubMenu').style.display = 'none';}}, 300);" style="top:0px;left:170px;width:120px;display:none;position:absolute;z-index:2;">
<div style="height:20px;width:100%;color:white;background-color:#1864ad;border:1px solid #3994c1;padding-top:7px;padding-bottom:7px;display:inline-block;">
Submenu1
</div>
<div style="height:20px;width:100%;color:white;background-color:#1864ad;border:1px solid #3994c1;padding-top:7px;padding-bottom:7px;display:inline-block;">
Submenu2
</div>
</div>
<div style="height:20px;width:100%;color:white;background-color:#10406e;border:1px solid #3994c1;padding-top:7px;padding-bottom:7px;display:inline-block;">
1
</div>
</div>
<div id="Menu2" style="top:0px;left:291px;width:170px;display:inline-block;;position:absolute;z-index:1;">
<div style="height:20px;width:100%;color:white;background-color:#10406e;border:1px solid #3994c1;padding-top:7px;padding-bottom:7px;display:inline-block;">
1_2
</div>
</div>
答案 0 :(得分:0)
你需要将z-index属性添加到子菜单文本div标签而不是带有“id = menu”的div,因为这个div也包含了悬停div的内容。
您的代码将是:
子菜单 图像/ small_right_arrow.png“&GT; Submenu1 Submenu2 1