Posted By Doteasy

Vertical menus are created in much the same way as horizontal menus, but they are even easier.

vertical menu

This menu:

  • items aligned vertically
  • items are displayed as blocks
  • block background color changes upon hover

To create the above menu, we will use CSS to style our basic list menu:

1. Remove all the default list styling.

ol, ul {
    list-style: none;
    }

2. Set the width and margin of the menu.

#mainmenu {
    margin: 10px;
    width: 120px;
    font-family: Tahoma;
    }

This time, the width will be much narrower as we are creating a vertical menu.

3. Set the list items to display as blocks. We will set the border properties by adding borders to the left, right and bottom edges. We will also add a border to the top of the first list item only. We will use the :first-child pseudo-class to do this.

#mainmenu li {
    display: block;
    border: 1px solid #333333;
    border-top: 0px;
    }

#mainmenu li:first-child {
    border-top: 1px solid #333333;
    }

4. Change the a element to block-level elements. We will also add some formatting styles and remove the underline with text-decoration: none.

#mainmenu a {
          display:block;
          padding:3px;
          text-decoration:none;
          color:#FFFFFF;
         }

5. Finally, we will change the hover state of the links so that they highlight when a user points to them.

#mainmenu a:hover {
          background-color:#8CC919;
          color:#FFFFFF;
         }

The Full CSS Code

So, to achieve the vertical menu, you will add the following lines to your CSS code. The below example is for an internal stylesheet, if you are using an external stylesheet, simply add the lines between <style type="text/css"> and </style> to your CSS file.

<head>
<style type="text/css">

            ol, ul {
                 list -style: none;
                }

             #mainmenu {
                margin: 10px;
                width: 120px;
                font- family: Tahoma;
                }

            #mainmenu li {
                display: block;
                border: 1px solid #333333;
                border-top: 0px;
                }
           
            #mainmenu li:first-child {
                border-top: 1px solid #333333;
                }

             #mainmenu a {
                  display:block;
                  padding:3px;
                  text-decoration:none;
                  background-color:#333333;
                  color:#FFFFFF;
                 }
 
             #mainmenu a:hover {
                  background-color:#8CC919;
                  color:#FFFFFF;
                 }
    </style>

</head>

Resources:

> Next time, we will try our hands on the dropdown menu.


 
3 Comment(s):
oes tsetnoc said...
i like vertical menus, will give this tutorial a try and if i am successful with it, i will use it in my sites.
November 22, 2009 09:05:06
 
link building said...
very nice article..thanks for posting...
June 15, 2009 02:49:25
 
Ramamoorthy said...
hi, this is very useful for Web site designers, i am also web designer i like very much if u want to visit my designs click http://www.dwtseo.com
June 8, 2009 10:00:28
 
Leave a Comment:
Name: * Email: *
Home Page URL:
Comment: *
   char left.

re-generate
Enter the text shown in the image on the left: *
 Remember Me?
* fields are requried
    


 
Google

Recent Entries
 
Category
 
Latest Comments
 
Archives
 
Free Tools and Applications
 
Doteasy Knowledge Base
 
 
Links
 
Doteasy Reviews
 
Visitors

You have 749806 hits.

 
$0 Web Hosting

$0 Web Hosting
 
 

Add to Technorati Favorites



Add to Google Reader or Homepage

Add to My AOL

Add to netvibes

Subscribe in Bloglines

Powered by FeedBurner