views:

31

answers:

1

Hi guys. I am trying to make drop down menu. Some folks help me on http://stackoverflow.com/questions/3314198/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;
}
+4  A: 

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;
}
Scott
very very nice...who would thought a little change of code could change the world....IE6...only 7% of the internet users use that junky browser...not my concern for now.....Thanks a lot.
Jerry
on your updated answer. I was wondering #menuBar li:hover .subMenu { display: block;} would make my submenu show up if I hover to #test1. or other li under #menuBar. However, When I tried it, everything worked great. Could you explain it for me?
Jerry
No, because the `li` you are hovering over is only one of those `li` elements at any one time, which is what activates the `.subMenu` contained within it.
Scott
I am not quite sure your "li elements at any one time," means. I guess it because #test2 is the only li that has .submenu ??
Jerry
Even if every `li` in a list has a `.subMenu`, the only one that will trigger to expose that submenu with the `li:hover` is the *one* element the user is hovering over at the moment, which will only be any one `li` at any one time.
Scott
Thanks a lot Scott.....
Jerry