Vertical List Menu

I used to find it hard to find a list menu that was compatible with all the browsers I use without having to use any CSS hacks that’s why when I created this one I decided to keep it and use it as my standard list menu, that way I only have to change certain aspects of the styling to make it look how I want it to look.

First of all we’ll do the HTML for the list menu, this will simply be:

<div class="listmenu">
<ul>
	<li><a href="#">List Item 1</a></li>
	<li><a href="#">List Item  2</a></li>
	<li><a href="#">List Item  3</a></li>
	<li><a href="#">List Item  4</a></li>
</ul>
</div>

And that’s it as far as the HTML for our list goes, if you’re confused now you might want to do some more reading on HTML. You can see the list so far Here. As you can see, it’s nothing special yet!
Now we’ll move onto the CSS. You might have noticed that our listmenu was inside a class called “listmenu” that’s simply so we can reuse the list menu as many times as we want on a single page, while using an ID would only let us use it once.
Here’s the code for the listmenu class:

.listmenu ul {
margin: 0 0 5px 0;
padding: 0 0 2px 0;
list-style-type: none;width:185px;}

All I have done here is added a little bit of padding and margin to space the whole list out from the side of the page, you can change this to whatever you need to make it fit your layout. I also added a width, pretty obvious what that does :p and a “list-style-type: none;” that will remove the bullet points from the end of the list. You can see what the whole list looks like now if you go Here. As you can see, there’s still some work to do!
Next we’re going to add the CSS to style the list item, this will only work on list items that are hyperlinked like the ones in the HTML code posted above. The code for the list item looks like this:

.listmenu li a {
color: #333;
display: block;
border-left:3px solid #666;
border-right:3px solid #666;
height: 16px;
padding: 4px 0 4px 14px;
text-decoration: none;
font-weight:bold;
background-color:#fff;}

The display:block; makes your browser put each list item on a new line rather than all on one line. The two borders simply add a 3px #666 border to either side of our list menu, they’re just there to make it look a bit nicer :p. The rest of the CSS is pretty self explanatory.

Here I added some extra CSS code:

html{
font:12px Arial, Helvetica, sans-serif;
color:#333;
padding:0;
margin:0;}

All the above code does is sets a font face, size and colour for the page to tidy it up a bit.

As you can see here the menu is starting to take shape now, all we need is a nice rollover effect.

To add the rollover we use this CSS:

.listmenu li a:hover {
background-color: #666;
color:#fff;}

All this does is change the background colour to #666 and the font colour to #fff when you put your mouse over it. If you take a look here you will see our list menu is complete! I’ll post the full code for the finished menu at the bottom of he page incase you get stuck.

If you liked this tutorial, please consider letting me know by posting a comment, and if you like RSS Feeds and tutorials like this, please sign up for my RSS Feed.

Vertical List Menu:

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<style type="text/css">
html{
font:12px Arial, Helvetica, sans-serif;
color:#333;
padding:0;
margin:0;}

.listmenu ul {
margin: 0 0 5px 0;
padding: 0 0 2px 0;
list-style-type: none;
width:185px;}

.listmenu li a {
color: #333;
display: block;
border-left:3px solid #666;
border-right:3px solid #666;
height: 16px;
padding: 4px 0 4px 14px;
text-decoration: none;
font-weight:bold;
background-color:#fff;}

.listmenu li a:hover {
background-color: #666;
color:#fff;}
</style>
<div class="listmenu">
<ul>
	<li><a href="#">List Item 1</a></li>
	<li><a href="#">List Item  2</a></li>
	<li><a href="#">List Item  3</a></li>
	<li><a href="#">List Item  4</a></li>
</ul>
</div>
This entry was posted in CSS Tutorials and tagged , , , , , . Bookmark the permalink. Both comments and trackbacks are currently closed.

27 Comments

  1. Aaron G
    Posted November 12, 2007 at 9:46 pm | Permalink

    I would like to thank you for putting this up! It’s a nice and simple tutorial for a great effect that I have been looking for for a long time.

  2. Arthur800
    Posted November 13, 2007 at 3:21 am | Permalink

    thank you very much!!!!!!! I really2 like it. It’s a nice tutorial. I can understand it easily.

  3. Posted November 13, 2007 at 3:21 am | Permalink

    No problem :)

  4. Danito
    Posted November 13, 2007 at 4:43 am | Permalink

    Yeah, great job.

    I’m french (scuse my english), i add your web page on my favorite ^^

  5. Posted November 14, 2007 at 6:26 pm | Permalink

    Why would you use a class for a single element? I know it doesn’t mean that much, but for people who are looking at this tutorial as one of the first things they learn in CSS it may be confusing.

  6. Posted November 15, 2007 at 3:29 am | Permalink

    You could use an ID if you wanted, however I thought people might want to use more than one list menu on a single page. This way it will be valid either way.

  7. Posted November 22, 2007 at 7:00 pm | Permalink

    Unless you require it for something else, you don’t need a div around a UL. A UL is in it’s own, essentially, a div.

  8. Ray
    Posted December 4, 2007 at 5:39 pm | Permalink

    I am new to CSS and found your tutorial very informative and explanations very useful. I am finding if difficult to find a similar comphrensive tutorial for horizantal menu’s.
    Maybe I am not using the attribute “display: inline;” correctly. In your article I understood the inclusion of the attribute “display: block;” makes each item go on a new line.

  9. Posted January 22, 2008 at 9:12 am | Permalink

    You don’t need to wrap a div tag round it. A UL tag is essentially a div in its own, so just assign the ID to the UL!

    cheers,

    Ewan

  10. Posted April 4, 2008 at 10:14 pm | Permalink

    thanks a lot..

  11. Posted April 4, 2008 at 10:15 pm | Permalink

    I need a horizatal menu and i dont understand css. Please help me!

  12. Posted April 5, 2008 at 8:46 am | Permalink

    For a horizontal list menu, please try: http://jamesowers.co.uk/css-tutorials/50/horizontal-css-list-menu/

    James’s last blog post..Diversifying My Blog

  13. joe harrington
    Posted May 19, 2008 at 10:32 pm | Permalink

    Thank you! this tutorial is perfectly set up, and is one of those things that actually explains something that is critical to today’s web development. ie; why have i seen list items being used for menus?? this is a concise and very helpful tutorial, thanks yo!

  14. Posted June 9, 2008 at 7:58 am | Permalink

    Great tutorial. Very easy to follow and the code worked perfectly.

  15. Thierry
    Posted October 2, 2008 at 10:56 pm | Permalink

    Is it possible to add a third color when we click the item menu? If yes, can you explain how?

  16. Posted May 8, 2009 at 4:23 am | Permalink

    Добрый день
    Это мое сообщение к администрации – jamesowers.co.uk,
    Обменяюсь баннерами с вашим сайтом , хочу чтобы они были в этот или можем обсудить другие варианты сотрудничества.
    Наш сайт forum-grad.ru
    На этот форум о Подмосковье заходят более 3000 человек, сайт развиваеться проводяться конкурсы, каждый день разыгриваються призы “100р на телефон” и мы готовы к сотрудничеству.
    контакты info(собака)forum-grad.ru
    p/s
    прошу извинить за вторжени

  17. Posted May 27, 2009 at 1:28 pm | Permalink

    Its a very useful tutorial, im currently settling into plenty of reading of CSS tutorials, ive used some basic CSS within a few wordpress themes before but im trying to get a better understanding so im absorbing tutorials like this one properly now.

    Thanks
    John

  18. Posted September 7, 2009 at 8:40 am | Permalink

    Спасибо, пригодилось))

  19. Posted November 10, 2009 at 8:19 am | Permalink

    nice article, thanks for your share..

  20. Posted February 14, 2010 at 12:35 am | Permalink

    nice article, thanks for sharing
    .-= prefabrik ev fiyatları´s last blog ..Satılık 78 Metrekare Çelik Ev =-.

  21. Posted April 16, 2010 at 9:14 pm | Permalink

    Thanks a lot.Good tutorial.
    .-= burak´s last blog ..Warez nedir?Seo da önemi =-.

  22. Posted July 6, 2010 at 12:49 pm | Permalink

    Thanks for your vertical list menu.

  23. Posted September 6, 2010 at 12:08 pm | Permalink

    Vertical List Menu post for thanx.

  24. Posted September 7, 2010 at 1:35 pm | Permalink

    merhaba böyle güzel konular açıp insanlara faydalı bir iş yaptığınız için çok teşekkür ederim!

  25. Posted September 29, 2010 at 10:35 am | Permalink

    thanks for this share… nice post…

  26. Posted September 30, 2010 at 3:53 pm | Permalink

    vertical list menu is nice, thanx.
    prezervatif´s last [type] ..Prezervatif Nedir

  27. Posted December 5, 2010 at 4:39 pm | Permalink

    Very useful, thanks

5 Trackbacks

  1. [...] View Tutorial [...]

  2. By Vertical List Menu - Tutorial Collection on June 8, 2009 at 9:37 pm

    [...] View Tutorial No Comment var addthis_pub=”izwan00″; BOOKMARK This entry was posted on Tuesday, June 9th, 2009 at 8:07 am and is filed under Css Tutorials. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site. [...]

  3. By +20 tutoriales CSS para principiantes | colorate on February 1, 2011 at 11:00 am

    [...] Menu Vertical en CSS [...]

  4. By CSS Tutorials for Beginners | Webpappa on February 4, 2011 at 11:07 am

    [...] I used to find it hard to find a list menu that was compatible with all the browsers I use without having to use any CSS hacks that’s why when I created this one I decided to keep it and use it as my standard list menu, that way I only have to change certain aspects of the styling to make it look how I want it to look…Read more [...]

  • Categories