悬停时的 CSS 子菜单背景
我想为自己制作一个小网站,所以我作为初学者问这个问题。将鼠标悬停在主菜单上时,我无法成功让子菜单包含另一个背景。
HTML:
<div id="nav">
<ul class="sub1">
<li><a href="#"><h2>Home</h2></a></li>
<li><a href="#"><h2>About</h2></a><!---id="onlink"--->
<ul class="sub2">
<li><a href="#" title="About Us">Us</a></li>
<li><a href="#" title="About Our product">Our product</a></li>
</ul>
</li>
</ul>
</div>
CSS:
#nav{
width:100%;
height: 60px;
padding-top: 20px;
padding-bottom: 10px;
}
#nav ul{
margin:0;
padding:0;
width: 60%;
margin: auto;
}
#nav ul li{
margin:0;
padding:0;
list-style: none;
float:left;
position:relative;
background:transparent url(EN/Button_menu_unselected.png);
}
#nav ul li ul li{
background:aqua; /*Test that doesn't work*/
}
#nav ul li a{
text-align:center;
text-decoration:none;
height:20px;
width:100px;
padding:10px;
display:block;
color:#003300;
}
#nav ul ul{
position:absolute;
visibility:hidden;
}
#nav ul li:hover ul{
visibility:visible;
}
#nav ul li:hover a{
background-image: url(EN/Button_menu_rollover.png);
}
下拉项的格式与名为“Button_menu_rollover”的按钮相同,这给了我一个非常糟糕的结果。
I want to make a small website for myself and so I ask this question as a beginner. I cannot succeed to have the submenu contain another background when hovering the main menu.
HTML:
<div id="nav">
<ul class="sub1">
<li><a href="#"><h2>Home</h2></a></li>
<li><a href="#"><h2>About</h2></a><!---id="onlink"--->
<ul class="sub2">
<li><a href="#" title="About Us">Us</a></li>
<li><a href="#" title="About Our product">Our product</a></li>
</ul>
</li>
</ul>
</div>
CSS:
#nav{
width:100%;
height: 60px;
padding-top: 20px;
padding-bottom: 10px;
}
#nav ul{
margin:0;
padding:0;
width: 60%;
margin: auto;
}
#nav ul li{
margin:0;
padding:0;
list-style: none;
float:left;
position:relative;
background:transparent url(EN/Button_menu_unselected.png);
}
#nav ul li ul li{
background:aqua; /*Test that doesn't work*/
}
#nav ul li a{
text-align:center;
text-decoration:none;
height:20px;
width:100px;
padding:10px;
display:block;
color:#003300;
}
#nav ul ul{
position:absolute;
visibility:hidden;
}
#nav ul li:hover ul{
visibility:visible;
}
#nav ul li:hover a{
background-image: url(EN/Button_menu_rollover.png);
}
The drop down items get the same format as the button called "Button_menu_rollover", which gives me a very bad result.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
代码:
适用于所有元素和子元素。
这修复了它,但此代码不适用于 IE6:
或者您可以使用 Javascript 实现悬停效果以获得准确的结果。
The code:
is applied to all elements and sub-elements.
This fixes it, but this code does not work on IE6:
Or you may use Javascript for HOVER effect to get exact results.