我找到了一个制作下拉菜单的指南,它说当你停止在主菜单项上悬停时,下拉菜单会保持不变。但是,我的菜单就消失了,无法按元素!
如您所见,音乐菜单位具有下拉(或在本例中为“右下拉”)菜单。
在这里 fiddle : http://jsfiddle.net/Gb2aS/
代码在这里:
HTML:
<!DOCTYPE HTML>
<html>
<head>
<link href="stylesheet.css" rel="stylesheet" type="text/css">
<title>Home</title>
</head>
<body>
<div ID="menubox">
<ul>
<li><a href="http://folk.ntnu.no/arnstekl/" class="link">Home</a></li>
<li><a href="#" class="link">Music</a>
<ul>
<li><a href="https://soundcloud.com/arnsteinkleven/" class="link">My music</a></li>
<li><a href="http://folk.ntnu.no/arnstekl/gilberto.html" class="link">The Joao Gilberto project</a></li>
</ul></li>
<li><a href="https://www.github.com/arnstein" class="link">Github</a></li>
<li><a href="http://www.flickr.com/photos/92472314@N03/" class="link">Pictures</a></li>
</ul>
</div>
<div ID="circle">
<p ID="title"> A <br> r <br> n <br> s <br> t <br> e <br> i <br> n </p>
</div>
</body>
</HTML>
CSS:
#menubox
{
width: 8%;
height: 30%;
border: 10% solid #C7D93D;
border-radius: 5%;
position: fixed;
margin-top: 12%;
margin-left: 18%;
font-family: Ubuntu, Lucida console, Futura;
list-style: none;
float: left;
}
#menubox ul li a
{
text-align: left;
font-size: 200%;
color: #FFF0A5;
}
#menubox ul li
{
color: #468966;
font-family: Ubuntu, Lucida console, Futura;
float: left;
margin-right: 10px;
position: relative;
}
#menubox ul
{
color: #468966;
font-family: Ubuntu, Lucida console, Futura;
}
#menubox ul ul
{
position: absolute;
left: -9999px;
list-style: none;
}
#menubox ul ul li
{
float: left;
margin-left: 40%;
position: relative;
font-size: 60%;
text-align: left;
}
#menubox ul ul a
{
white-space: nowrap;
}
#menubox ul li:hover a
{
text-decoration: none;
color: #FFB03B;
}
#menubox ul li:hover ul
{
left: 0;
}
#menubox ul li:hover ul a
{
text-decoration: none;
color: #FFB03B;
}
#menubox ul li:hover ul li a:hover
{
color: #FFB03B;
}
div p
{
color: #FFF0A5;
text-align: center;
position: relative;
vertical-align: middle;
display: inline-block;
margin-top: 300px;
line-height: 60px;
}
#circle
{
border-radius: 100%;
-webkit-border-radius: 100%;
-moz-border-radius: 100%;
background-color: #B64926;
width: 500px;
height: 500px;
display: block;
position: fixed;
margin-top: 9%;
margin-left: 52%;
text-align: center;
}
#title
{
text-color: #FFF0A5;
font-size: 350%;
display: inline;
text-align: center;
}
body
{
height: 100%;
width: 100%;
background-color: #468966;
font-family: Ubuntu, Lucida console, Futura;
}
.link
{
text-color: #FFF0A5;
text-decoration: none;
text-align: left;
}
最佳答案
问题是因为你的子列表是偏移的,所以有光标必须从主菜单项和子菜单穿过的死区。这将解决您的问题:
#menubox ul li:hover ul
{
left: 0;
top: 0;
z-index:100;
}
正如 Daniel Gimenez 在上面解释的那样,子菜单保持可见的原因是因为它是主 ul 元素的子项,因此如果您将光标停留在子菜单上,浏览器会将其视为将光标保持在原始菜单上菜单项,并且 :hover css 仍然存在。
它对于下拉菜单/弹出菜单非常有效,因为即使子对象在物理上显示在其父对象之外,从代码的 Angular 来看它仍然在父对象“内部”。但是,如果两者之间存在任何物理间隙并且鼠标越过该间隙,则 :hover 规则将被停用并且子菜单将消失。
关于html - 不将鼠标悬停在下拉式菜单上时,使下拉式菜单保持不变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17367924/