Just about every web-site, blog, or online application I have ever been to in my life has had some type of navigation. The only problem is that sometimes the navigation bar has been built with tables or divs that take a lot of extra code and don’t expand well when the user enlarges the text.
The Solution
One of first techniques I learned when I started writing my own CSS was using an unordered list for all navigation. For vertical or horizontal navigation a list is your solution. The code is very light weight, semantic, and flexible. Here are some examples of lists being used for navigation:





A lot of you might have previously thought that lists could only be vertical. Initially they are, but with one CSS property we can flatten out that list to make a nav-bar instead of a nav-column.
The Process
To start off make an unordered list with the the text linked to their destination.
<ul id=”nav_bar”>
<li><a href=#>Link Text1</a></li>
<li><a href=#>Link Text2</a></li>
<li><a href=#>Link Text3</a></li>
<li><a href=#>Link Text4</a></li>
</ul>
Note that I put the <a href></a> inside of the <li></li> html tags.
Give the unordered list an id of “nav_bar”. So many times people will wrap their navigation in div tags to help position the list, but you can apply all the same CSS properties to the actual unordered list so the need for the div is unnecessary.
Here is what you should have so far. I highlighted the background so you could see the entire UL.
In your CSS file or wherever you are placing your styles add an id for nav_bar. There you can position, add margin or padding, or whatever you feel like.
Above I mentioned that there was one CSS property that would flatten that vertical list out. On the line below the nav_bar id add this style:
#nav_bar li {
display:inline;
list-style:none;
}
This style accompanied by both properties does two things. The first is to display each line item inline instead of vertically. The second is to get rid of the bullet point to the left of each line item.
See Second Example
Now to give each link more of a button feel we can add some extra padding/margin to each anchor element, which in turn also makes the clickable area bigger and easier to hit. The code:
#nav_bar a {
background:yellow;
padding:10px;
margin:10px;
}
And for further differentiation adding the pseudo style :hover to the element you can change, say, that background color to tell the user which link they are hovering over by placing this below the previous style.
#nav_bar a:hover {
background:green;
}
The page should now look like this.
You might notice that the link buttons have grown outside of the ul. (The yellow is outside of the grey.)
The simple fix for this is to add a float property (right or left) to both “#nav_bar” and “#nav_bar a”. This makes it so that the links push out the walls of the ul aka #nav_bar when they are resized. Making the whole navigation bar very versatile when dealing with different text sizes.
Well there you have it. The final product. all there is left to do is play with the colors, margins, padding, and background images. In a later post I will get to adding background images to make tabs/rounded corners and such.