在哪里正确应用 :hover 以使子菜单 css 保持悬停状态
我正在尝试制作下拉菜单。有些人帮助了我 仅 CSS 下拉菜单帖子。
一切正常,除了当我将鼠标悬停在子菜单上时。我的 #menubar #test2 a:hover
中的悬停状态背景图像将返回到 #menubar #test2 a
状态。我真的需要完成这件事,如果有人能帮助我,我将不胜感激。谢谢一百万。
我的 HTML
<ul id="menuBar">
<li id="test1">test1</li>
<li id="test2"><a href="#">Pro1</a>
<div class="subMenu">
<ul>
<li><a href="#">sub1</a></li>
<li><a href="#">sub2</a></li>
<li><a href="#">sub3</a></li>
</ul>
<ul>
<li><a href="#">Volleyball</a></li>
<li><a href="#">Walking</a></li>
<li><a href="#">Water Shoes</a></li>
</ul>
</div> <!--end of submenu-->
</li>
</ul>
CSS
#menuBar #test2 a{
background:url("../images/btTest.jpg") no-repeat bottom;
display:block;
border-right:1px solid #ffffff;
width:112px;
height:37px;
}
#menuBar #test2 a:hover{
background:url("../images/btTest.jpg") no-repeat top;
}
#menuBar #test2 a:hover + .subMenu { //submenu show up
display:block;
}
#menuBar li .subMenu:hover { //keep submenu show up when hover in submenu
display: block;
}
//the next one is not working....but I can't think of anything....
#menuBar li .subMenu:hover #menuBar #mens a {
background:url("../images/btMen.jpg") no-repeat top;
}
I am trying to make drop down menu. Some folks helped me on
CSS only drop down menu post.
Everything works fine except when I hover my mouse to my submenu. The hover state background image in my #menubar #test2 a:hover
will return to #menubar #test2 a
state. I really need to get this done and would appreciate if anyone could help me about it. Thanks a million.
My html
<ul id="menuBar">
<li id="test1">test1</li>
<li id="test2"><a href="#">Pro1</a>
<div class="subMenu">
<ul>
<li><a href="#">sub1</a></li>
<li><a href="#">sub2</a></li>
<li><a href="#">sub3</a></li>
</ul>
<ul>
<li><a href="#">Volleyball</a></li>
<li><a href="#">Walking</a></li>
<li><a href="#">Water Shoes</a></li>
</ul>
</div> <!--end of submenu-->
</li>
</ul>
CSS
#menuBar #test2 a{
background:url("../images/btTest.jpg") no-repeat bottom;
display:block;
border-right:1px solid #ffffff;
width:112px;
height:37px;
}
#menuBar #test2 a:hover{
background:url("../images/btTest.jpg") no-repeat top;
}
#menuBar #test2 a:hover + .subMenu { //submenu show up
display:block;
}
#menuBar li .subMenu:hover { //keep submenu show up when hover in submenu
display: block;
}
//the next one is not working....but I can't think of anything....
#menuBar li .subMenu:hover #menuBar #mens a {
background:url("../images/btMen.jpg") no-repeat top;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要这样:
成为这样:
当您移动到
.subMenu
时让它保持不变。这不适用于 IE6(如果你关心的话)。还有这些:
应该可以替换为:
You need this:
To be this:
To get it to stick when you move to the
.subMenu
. This will not work for IE6 (if you care).Also these:
Should be able to be replaced with just this: