0
votes

I have designed a 2-Level CSS drop down menu. Everything works perfect except only one thing. I want it so that when I hover over the top menu item, the 1st level drop down menu appears and when I hover over the item Press in the 1st level menu then the 2nd level menu items appear. But the problem is that when I hover over the top menu all sub-menus appear altogether. That means the display: none does not work. Why does it happen and what is the solution?

jsfiddle.net

HTML Code

<ul id="nav">
 <li><a href="/ueber_uns.htm">About Us</a>
  <ul>
    <li><a href="#">Who We Are</a></li>
    <li><a href="#">Our Goals</a></li>
    <li><a href="#">Our Team</a></li>
    <li><a href="#">Press</a>
     <ul>
      <li><a href="#">2006</a></li>
      <li><a href="#">2007</a></li>
      <li><a href="#">2008</a></li>
     </ul>
    </li>
   <li><a href="#">Impressum</a></li>
  </ul>
 </li>
</ul>

CSS Code

ul#nav 
{
margin: 0;
padding: 0;
list-style: none;
text-align: center;
/*display: table-cell;
vertical-align: middle;*/
}
ul#nav li
{
float: left;
position: relative;
font-size: 16px;
background-color: orange;
}
ul#nav li li
{
font-size: 14px;
}
ul#nav ul 
{
margin: 0;
padding: 0;
list-style: none;
text-align: left;
display: none;
}
ul#nav li:hover ul 
{
display: block;
position: absolute;
}
ul#nav a:link, ul#nav a:visited
{
display: block;
width: 110px;
padding: 10px 5px;
text-decoration: none;
color: #000;
}
ul#nav ul a:link, ul#nav ul a:visited 
{
width: 135px;
}
ul#nav a:hover, ul#nav a:active
{
color: #fff;
}
ul#nav ul ul
{
position: absolute;
top: 0;
left: 100%;
display: none;
}
ul#nav ul li:hover ul
{
display: block;
}
3

3 Answers

2
votes

Change this

ul#nav li:hover ul 
{
display: block;
position: absolute;
} 

to this

ul#nav li:hover > ul 
{
display: block;
position: absolute;
}

Example

Basically what ul#nav li:hover > ul does is that it targets the secondary drop-down menu only, so when you hover over about us, only the second level menu is going to show up, leaving the third one hidden.

1
votes

This

li:hover ul

will apply to all descendant ul. Change it to this:

li:hover>ul

to apply to direct descendant.

0
votes