在哪里正确应用 :hover 以使子菜单 css 保持悬停状态

发布于 2024-09-10 21:41:23 字数 1658 浏览 1 评论 0原文

我正在尝试制作下拉菜单。有些人帮助了我 仅 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

厌味 2024-09-17 21:41:23

您需要这样:

#menuBar #test2 a:hover{
   background:url("../images/btTest.jpg") no-repeat top;
} 

成为这样:

#menuBar #test2:hover a {
  background:url("../images/btTest.jpg") no-repeat top;
}

当您移动到 ​​.subMenu 时让它保持不变。这不适用于 IE6(如果你关心的话)。

还有这些:

#menuBar #test2 a:hover + .subMenu { //submenu show up
  display:block;
} 

#menuBar li .subMenu:hover {  //keep submenu show up when hover in submenu
  display: block; 
}

应该可以替换为:

#menuBar li:hover .subMenu {
  display: block;
}

You need this:

#menuBar #test2 a:hover{
   background:url("../images/btTest.jpg") no-repeat top;
} 

To be this:

#menuBar #test2:hover a {
  background:url("../images/btTest.jpg") no-repeat top;
}

To get it to stick when you move to the .subMenu. This will not work for IE6 (if you care).

Also these:

#menuBar #test2 a:hover + .subMenu { //submenu show up
  display:block;
} 

#menuBar li .subMenu:hover {  //keep submenu show up when hover in submenu
  display: block; 
}

Should be able to be replaced with just this:

#menuBar li:hover .subMenu {
  display: block;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文