This tutorial will show you how to make a horizontal CSS list menu. No images, no javascript. Just a simple, cross browser compatible CSS list menu! If you want to see the finished product or you just want the code, look here.
First of all we’ll need the HTML for our list menu, this is just a normal unordered list.
<div class="menu"> <ul> <li><a href="#">Home</a></li> <li><a href="#">Link</a></li> <li><a href="#">Link</a></li> <li><a href="#">Link</a></li> <li><a href="#">Link</a></li> </ul> <br style="clear:left"/> </div>
It’s just a simple html page with an unordered list menu on. You might notice I’ve added a div called menu around the list, I like to do this as it helps me remember what part of the code does what if I ever have to go back to it.
Next we’re going to add the CSS code for the div called menu that surrounds the list.
.menu{
width: 100%;
background-color: #333; }
Again this is nice and simple. The menu div will be the full width of the div it’s inside and will have a dark grey background.
Next we add the syling for the list and the list items.
.menu ul{
margin: 0; padding: 0;
float: left;}
.menu ul li{
display: inline;}
.menu ul li a{
float: left; text-decoration: none;
color: white;
padding: 10.5px 11px;
background-color: #333; }
.menu ul li a:visited{
color: white;}
.menu ul li a:hover, .menu ul li .current{
color: #fff;
background-color:#0b75b2;}
Again it’s all pretty simple, you should be able to understand the code with a little bit of CSS knowledge. Have a tinker with the code if you’re unsure about something.
You might also want to sign up for the RSS Feed or view some of my other CSS Tutorials
34 Comments
Yet again, this works like a charm. Good job.
good work i was looking for this thanks
Great!
Works wonderfully!
:)
Thank You, It’s nice and simple
simple as everybody wants!
thanks
I can’t get it to work! I copy and paste exactly the way it is. The html code makes a list but when i enter the css code it does nothing.
Could you upload your site and post the link?
Jamess last blog post..Automatically published articles with WordPress
this is the best
but how can i add a submenu to it?
It works! It didn’t work at first but I figured it out by replacing the class function to div in css…!
Thanks a lot for the simplicity!
Do you have anything on 2 level, horizontal CSS nav bars?
SaminOzs last blog post..Element (Tag) attributes in XHTML
Hey,it’s quite simple and easy,but i can’t center it. Can you tell me how i can do it? it’s a bit urgent.
Awesome thank you!
Saved me mucking about!!
This CSS tutorial has solved my problem. Thank you!
By the way, would you happen to have one with a 2nd-level hierarchy for each menu link?
How do you add submenus?
Thank you! This is probably the most intuitive, easy to follow tut for horizontal list menus. Much appreciated, and thanks for sharing.
Is it possible to create the menu then place it all into a single ccs sheet so that it works on every page autimatically.
Yes you would just put your code in a separate CSS file and then include the CSS file between the head tags of each html document you want it in.
To include the CSS file, use the code (code moved to pastebin: http://pastebin.com/mf1ccb51 ) when the name of your CSS file is style.css.
Thanks, works great. However, how do you center it?
Good One
but how can i add a sub menu to it ?
ow man this is exactly what i like about these tuts, simpl & basic! With this you can experiment to get your own result fast, which is way more easy then recoding too-complicated examples with the basics somewhere in it. Thanks again!
These really helped me to build my homepage, I can really appreciated if people take some time and write a usefull tutorial.
thank you thank you.
I am just learning to find my way through css and this is exactly what I needed!!!!
This is a neat clean horizontal menu. I will be implementing it in the church website today.
Hey thanks bro! worked great! and simple to follow
works just perfectly.. thanks a lot for the tip..
Brilliant – cleared some things up for me. Very straightforward and well layed out. Thanks very much…
VERY NICE! THANKS!
Simple, clean code – good job
hai.. i have one doubt. css list-menu differ in different browser like firefox and ie. pls solve my problem……
How to make horizontal list catogery likes MP3 category A – Z?
Wirobrojo´s last [type] ..Memperkuat Keyword Dengan Tag Alt
Nice one for a simple straight forward tutorial.
Hey its really owesome…..thanx
simple and straight forward menu.
Sorry mate.
It wont work properly in firefox. it will alway position on the top of div. We can’t move the list content on the center of “menu” div. margin or padding will not help in this case. we need to do some other css hack.
my testing environment are:
Firefox 3.6.16
Ubuntu 10.04
One Trackback
[...] For those of you that want to try something more advanced, check out the code for this horizontal list menu. [...]