Reputation: 556
i have an unordered list with 2 levels, and i would like to hide "first level submenus" and show them only when "first level" li is hover.
here,s the code :
<ul>
<li>first level</li>
<ul>
<li>first level submenuitem 1</li>
<li>first level submenuitem 2</li>
</ul>
<li>another list item</li>
</ul>
how can i do that with pure CSS selectors ?
Upvotes: 0
Views: 1746
Reputation: 7515
I would use jQuery
<ul>
<li class="show">first level</li>
<ul class="child" style="display: none;">
<li>first level submenuitem 1</li>
<li>first level submenuitem 2</li>
</ul>
<li class="show">another list item</li>
</ul>
<script type="text/javascript" >
$(".show").hover(function() {
$(this).find('.child').show();
});
</script>
Upvotes: -1
Reputation: 4348
Something like this:
ul ul {display: none;}
ul li:hover ul {display: block;}
If you might have more than two levels then you might wanna be more specific, for say:
ul li > ul {display: none;}
ul li:hover > ul {display: block;}
Upvotes: 3