Vertical Drop Down Menu on Hover Using CSS and HTML

Introduction

 
This article explains how to create a Vertical Drop Down Menu using CSS and HTML.
 
You often see sites containing a menu bar that drops down when hovered over and that looks really great but those are usually horizontal Drop Down Menus, this article will help you to create a Vertical Drop Down Menu.
 
Its output will be something like this:
 
Animation1.gif
 
Now we will see the procedure to create such a Drop Down Menu.
 
Step 1
 
First of all, add a Style Sheet and a form or HTML page.
 
Then on the HTML page or the Web Form of .NET add a "Div" and name it as "divMenu".
 
After creating the Div we need to add a list of items and another list in those items, so it's final code will be something like this:
  1. <div id="divMenu">    
  2. <ul>    
  3.     <li><a href="#">Home1</a>    
  4.     <ul>    
  5.         <li><a href="#">Homea</a></li>    
  6.         <li><a href="#">Homeb</a></li>    
  7.         <li><a href="#">Homec</a></li>    
  8.     </ul>    
  9.         </li>    
  10.     <li><a href="#">Home2</a>    
  11.             <ul>    
  12.         <li><a href="#">Homed</a></li>    
  13.         <li><a href="#">Homee</a></li>    
  14.         <li><a href="#">Homef</a></li>    
  15.     </ul></li>    
  16.     <li><a href="#">Home3</a>    
  17.             <ul>    
  18.         <li><a href="#">Homeg</a></li>    
  19.         <li><a href="#">Homeh</a></li>    
  20.         <li><a href="#">Homei</a></li>    
  21.     </ul></li>    
  22.     <li><a href="#">Home4</a></li>    
  23.     <li><a href="#">Home5</a>    
  24.             <ul>    
  25.         <li><a href="#">Homej</a></li>    
  26.         <li><a href="#">Homek</a></li>    
  27.         <li><a href="#">Homel</a></li>    
  28.     </ul></li>    
  29.     <li><a href="#">Home6</a></li>    
  30. </ul>    
  31. </div>   
Step 2
 
Right now your code is nothing more than this:
 
cssdrop5.jpg
 
So to make it look good and interesting we will makechanges in the Style Sheet that we had added earlier.
 
Add this code to your Style Sheet:
  1. #divMenu, ul, li, li li {  
  2.     margin0;  
  3.     padding0;  
  4. }  
  5.    
  6. #divMenu {  
  7.     width150px;  
  8.     height27px;  
  9. }  
  10.    
  11. #divMenu ul  
  12. {  
  13.      line-height25px;  
  14. }  
  15.    
  16.     #divMenu li {  
  17.         list-stylenone;  
  18.         positionrelative;  
  19.         background#641b1b;  
  20.     }  
  21.    
  22.         #divMenu li li {  
  23.             list-stylenone;  
  24.             positionrelative;  
  25.             background#641b1b;  
  26.             left: 148px;  
  27.             top: -27px;  
  28.         }  
  29.    
  30.    
  31.     #divMenu ul li a {  
  32.         width148px;  
  33.         height25px;  
  34.         displayblock;  
  35.         text-decorationnone;  
  36.         text-aligncenter;  
  37.         font-family: Georgia,'Times New Roman',serif;  
  38.         color:#ffffff;  
  39.         border:1px solid #eee;  
  40.     }  
  41.    
  42.     #divMenu ul ul {  
  43.         positionabsolute;  
  44.         visibilityhidden;  
  45.         top: 27px;  
  46.     }  
  47.    
  48.     #divMenu ul li:hover ul {  
  49.         visibilityvisible;  
  50.     }  
  51.    
  52.     #divMenu li:hover {  
  53.         background-color#945c7d;  
  54.     }  
  55.    
  56.     #divMenu ul li:hover ul li a:hover {  
  57.         background-color#945c7d;  
  58.     }  
  59.    
  60.     #divMenu a:hover {  
  61.         font-weightbold;  
  62.     } 
Here I used the ID of the <Div>, in other words "divMenu".
 
Now everything will be changed and your output will be totally different and interesting.
 
Output
 
Animation1.gif