css3 - Drop-down menu using CSS -


i newbie in web programming! have been working on drop down menu , have got:

html code

<!doctype html> <head> <title>drop down menu</title> <link rel="stylesheet" type="text/css" href="style.css" /> </head> <body> <h1>drop down menu</h1> <hr> <div>   <ul id="nav">     <li><a href="#">home</a></li>     <li><a href="#">categories</a>       <ul id="sub">          <li><a href="#">photoshop</a></li>          <li><a href="#">design</a></li>          <li><a href="#">web</a></li>           <ul id="sub2">             <li><a href="#">html</a></li>             <li><a href="#">css</a></li>           </ul>       </ul>     </li>     <li><a href="#">popular</a></li>     <li><a href="#">contact</a></li>   </ul>  </div> </body> </html>` 

css code

#nav{     list-style:none;     font-weight:bold;     margin-bottom:10px;     float:left;     width:100%;     position:relative;     z-index:5; } #nav li{     float:left;     margin-right:10px;     position:relative; } #nav a{     display:block;     padding:5px;     color:#fff;     background:#333;     text-decoration:none; } #nav a:hover{     color:#fff;     background:#6b0c36;     text-decoration:underline; } #nav #sub{     background:#fff;      background:rgba(255,255,255,0);      list-style:none;     position:absolute;     left:-9999px;  } #nav #sub li{     padding-top:1px;     float:none; } #nav #sub a{     white-space:nowrap;  } #nav li:hover #sub{      left:0;  }  #nav li:hover #sub #sub2 {     background:#fff;     background:rgba(255,255,255,0);     list-style:none;     position:absolute;     display: none; }  #nav #sub li:hover #sub2{     display:block; }  #nav li:hover a{      background:#6b0c36;     text-decoration:underline; } #nav li:hover #sub a{      text-decoration:none; } #nav li:hover #sub li a:hover{      background:#333; } 

my problem on hovering on web sub-block, html , css ul doesn't show. doing wrong?

please find below jsfiddle link http://jsfiddle.net/d9udt/

part of updated html

<li><a href="#">web</a>             <ul id="sub2" class="submenu">               <li><a href="#">html</a></li>               <li><a href="#">css</a></li>             </ul>          </li> 

part of updated css

#nav ul.submenu{     background:#fff;      background:rgba(255,255,255,0);      list-style:none;     position:absolute;     left:-9999px;  }   #nav li:hover > ul.submenu{      left:0;  } 

1) seems markup bit wrong

<li><a href="#">web</a></li>           <ul id="sub2">             <li><a href="#">html</a></li>             <li><a href="#">css</a></li>           </ul> 

this should this

<li><a href="#">web</a>             <ul id="sub2" class="submenu">               <li><a href="#">html</a></li>               <li><a href="#">css</a></li>             </ul>          </li> 

2) instead of adding styles id can add them class same class can use on other drop down list well

hope helps!


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -