Tutorial Related Links
If you wish to view a full list of all the tutorials that have been posted by Tony Bob Design
or wish to browse our arhives, click on the links above.
Categories
If you wish to browse our tutorials by category, navigate with the links above.
Tutorials - CSS - Horizontal Navigation
Posted by:Tony Bob on Oct 04 2006
To make use of this tutorial, you must have some prior knowledge of common html markup and basic css rules.
Click here to see the final result
Firstly we will deal with sorting out our links
<ul>
<li><a href="http://www.tonybobdesign.com/#">Home</a></li>
<li><a href="http://www.tonybobdesign.com/#">News</a></li>
<li><a href="http://www.tonybobdesign.com/#">About</a></li>
<li><a href="http://www.tonybobdesign.com/#">Services</a></li>
<li><a href="http://www.tonybobdesign.com/#">Links</a></li>
<li><a href="http://www.tonybobdesign.com/#">Contact</a></li>
</ul>
</div>
You do not have to use a div, you can also use it within a table cell. The above code just sets out your links using bullet points.
Apply border to div or td tag
border:1px solid #FFFFFF;
}
I am using an ID (note the #), you could also use a class (which would use a . instead) if you are using multiple duplicated navigation bar use the class so you won't have any problems with W3C validation.
Now we will apply some CSS to format the layout to our ul tag
width:100%;
background-color:#6699cc;
padding-left:0;
margin:0;
float:left;
}
This keeps the navigation bar to the left with the float tag. It also stretches the whole page/table cell. The margins and padding allow the lists to lose their default formatting.
Now we need to format each li tag.
display:inline;
}
This will make all the items in the li tags lined up next to each other rather than on seperate lines.
Now we need to apply some CSS for our links within the li tags
float:left;
color:#FFFFFF;
padding:6px 12px 6px 12px;
border-right:1px solid #FFFFFF;
}
This applies padding to each link to make it look more like a button rather than a short link. With the padding, the first figure is the top padding, followed by the right padding, followed by the bottom then the left padding. The border-right seperates each link with a small border which uses the full height of the navigation bar which makes the links look more like buttons.
Add a rollover
background-color:#336699;
}
This will change the background colour to a dark blue.
Click here to see the final result
Firstly we will deal with sorting out our links
Step 1
Code
<div id="nav"><ul>
<li><a href="http://www.tonybobdesign.com/#">Home</a></li>
<li><a href="http://www.tonybobdesign.com/#">News</a></li>
<li><a href="http://www.tonybobdesign.com/#">About</a></li>
<li><a href="http://www.tonybobdesign.com/#">Services</a></li>
<li><a href="http://www.tonybobdesign.com/#">Links</a></li>
<li><a href="http://www.tonybobdesign.com/#">Contact</a></li>
</ul>
</div>
You do not have to use a div, you can also use it within a table cell. The above code just sets out your links using bullet points.
Apply border to div or td tag
Step 2
Code
#nav{border:1px solid #FFFFFF;
}
I am using an ID (note the #), you could also use a class (which would use a . instead) if you are using multiple duplicated navigation bar use the class so you won't have any problems with W3C validation.
Now we will apply some CSS to format the layout to our ul tag
Step 3
Code
#nav ul{width:100%;
background-color:#6699cc;
padding-left:0;
margin:0;
float:left;
}
This keeps the navigation bar to the left with the float tag. It also stretches the whole page/table cell. The margins and padding allow the lists to lose their default formatting.
Now we need to format each li tag.
Step 4
Code
#nav ul li{display:inline;
}
This will make all the items in the li tags lined up next to each other rather than on seperate lines.
Now we need to apply some CSS for our links within the li tags
Step 5
Code
#nav ul li a{float:left;
color:#FFFFFF;
padding:6px 12px 6px 12px;
border-right:1px solid #FFFFFF;
}
This applies padding to each link to make it look more like a button rather than a short link. With the padding, the first figure is the top padding, followed by the right padding, followed by the bottom then the left padding. The border-right seperates each link with a small border which uses the full height of the navigation bar which makes the links look more like buttons.
Add a rollover
Step 6
Code
#nav ul li a:hover{background-color:#336699;
}
This will change the background colour to a dark blue.
Rate This Tutorial
Comments
Add A comment










