Saturday, November 20, 2010

CSS Horizontal List Menu

This tutorial will show you how to make a horizontal CSS list menu. in this tutorial we are not using images or javascript. Just a simple, cross browser compatible CSS list menu.

First of all we will need the HTML for our list menu, this is just a normal unordered list.

Example:
<div class="menu">
<ul>
<li><a href="http://w3schoolss.blogspot.com/">Home</a></li>
<li><a href="http://w3schoolss.blogspot.com/">About</a></li>
<li><a href="http://w3schoolss.blogspot.com/">Contact</a></li>
<li><a href="http://w3schoolss.blogspot.com/">Links</a></li>
<li><a href="http://w3schoolss.blogspot.com/">HTML</a></li>
</ul>
</div>

in above example I have added a div called menu around the list, I want to do because it helps me remember what part of the code does what, if I ever do it again. Then let's add some CSS to the div called menu surrounding the list.

.menu{
width: 100%;
font-family:Verdana, Arial, Helvetica, sans-serif;
font-size:12px;
color:#ffffff;
background-color: #333; }

Again, this is a nice and easy. Class menu cover the entire width of the div is inside and has a dark gray background with font(Verdana, Arial, Helvetica, sans-serif), font size(12px).

Then we add to the list Style and elements of the list.

.menu ul{
margin: 0; padding: 0;
float: left;}

.menu ul li{
display: inline;}

.menu ul li a{
text-decoration: none;
color:#ffffff;
float: left;
background-color: #333;
padding: 10px 10px;
 }

.menu ul li a:visited
{
color:#ffffff;
}

.menu ul li a:hover, .menu ul li .current
{
color: #fff;
background-color:#0b75b2;
}

Once again, it's all quite simple, you should be able to understand a little &#39;skill CSS code.

This results in:

No comments:

Post a Comment