我有一个纯 CSS 菜单(不需要 javascript),带有 HTML:
<ul id="nav">
<li>
<div><a href="#">First Menu</a>
</div>
<ul>
<li><a href="#">First Option</a></li>
<li><a href="#">Second Option</a></li>
<li id="subnav"><a href="#">Sub Menu —>></a>
<ul>
<li><a href="#">First Sub Option</a></li>
<li><a href="#">Second Sub Option</a></li>
<li><a href="#">Third Sub Option</a></li>
<li><a href="#">Fourth Sub Option</a></li>
</ul>
</li>
<li><a href="#">Third Option</a>
</li>
<li id="subnav"><a href="#">Second Sub Menu —>></a>
<ul>
<li><a href="#">Second Sub Menu, First Sub Option</a></li>
<li><a href="#">Second Sub Menu, Second Sub Option</a></li>
</ul>
<li><a href="#">Fourth Option</a></li>
</li>
</ul>
</li>
<li>
<div><a href="#">Second Menu</a>
</div>
<ul>
<li><a href="#">Next First Option</a></li>
<li><a href="#">Next Second Option</a></li>
</ul>
</li>
</ul>
和CSS:
#nav, #nav a {
text-decoration: none;
text-transform: uppercase;
color: #000;
padding: 0px 1px 0px 1px;
margin: 0px;
border: black thin solid;
text-decoration: none;
font-weight: bold;
font-style: italic;
font-size: 115%;
list-style-type: none;
font-family: sans-serif;
margin-left: none;
background-color: #EFAA0D;
z-index:100;
}
#nav>li {
float: left;
}
#nav li ul {
list-style-type: none;
display: none;
width:20em;
position: absolute;
left: 4px;
font-weight: normal;
}
#nav li>ul {
top: auto;
left: auto;
}
#nav li:hover>ul {
display: block;
}
#nav li a:hover {
background-color: #fdca2e;
}
#nav li a:link, #nav li a:visited {
padding: 0em .25em 0em 0.25em;
border: black thin solid;
text-decoration: none;
display: block;
left:2px;
}
#nav li>a {
font-weight: normal;
}
#subnav li a:link, #subnav li a:visited {
color: #EFAA0D;
padding: 0em .25em 0em 0.25em;
border: green thin solid;
display: block;
left:2px;
background-color: black;
}
#subnav li a:hover {
background-color: #555;
position: relative;
left: 1px;
}
请看小提琴:http: //jsfiddle.net/sablefoste/wRK9v/7/
我担心的是查看“第三选项”及其他选项。当试图访问这些选项时,它会被“第二个选项”的子菜单覆盖。访问的唯一方法是将鼠标滑过填充。
有没有办法来解决这个问题?