Create a menu using pure css and HTML -


i have menu structure :

<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 hover on item1 subitem1,subitem2,subitem3,subitem4 need display , subitem5 - 8 no need display.

when hover on item2, subitem5 - 8 need display. how can achieve using css?

i have tried:

ul.menu ul{  display: none; } ul.menu li:hover:first-child ul {   display:block; } 

html

<ul class="menu">   <li>     item1     <ul>       <li><a href="#">subitem1</a></li>       <li><a href="#">subitem2</a></li>       <li><a href="#">subitem3</a></li>       <li><a href="#">subitem4</a></li>       <li>         item2         <ul>           <li><a href="#">subitem5</a></li>           <li><a href="#">subitem6</a></li>           <li><a href="#">subitem7</a></li>           <li><a href="#">subitem8</a></li>         </ul>       </li>     </ul>   </li> </ul> 

css

.menu li > ul {     display:none; }  .menu li:hover > ul {     display:block; } 

live


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -