I have a menu structure like this :
<ul class"menu">
<li>
<a>item1</a>
<ul>
<li><a>subitem1</a></li>
<li><a>subitem2</a></li>
<li><a>subitem3</a></li>
<li><a>subitem4</a></li>
<li>
<a>item2</a>
<ul class="sub-ul-2">
<li><a>subitem5</a></li>
<li><a>subitem6</a></li>
<li><a>subitem7</a></li>
<li><a>subitem8</a></li>
</ul>
</li>
</ul>
</li>
</ul>
My requirement is, when I hover on item1 then subitem1,subitem2,subitem3,subitem4 only need to display and subitem5 - 8 no need to display.
When I hover on item2, then only subitem5 - 8 need to display. How can I achieve this by using css?
I have tried:
ul.menu ul{
display: none;
}
ul.menu li:hover:first-child ul {
display:block;
}
Something like this? (Without changing your html)
CSS:
DEMO 1
Update: (Without using any classes & cursos:pointer;)
DEMO 2
Or the short css, after fixing the first ul from
<ul class"menu">
to<ul class="menu">
(By adding the = to it)DEMO 3
fiddle: http://jsfiddle.net/Z22kH/
html:
css:
HTML
CSS
LIVE
I've put together a working and minimalistic jsfiddle demo.
You hide all UL's inside
.menu
. Upon hovering any list-item, you reveal any direct descendant UL. I usedisplay: block;
anddisplay: none;
for the purpose of keeping it simple.CSS: