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 - Vertical 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
Set up links for the navigation bar
<a href="#">Link2</a><br>
<a href="#">Link3</a><br>
<a href="#">Link4</a><br>
<a href="#">Link5</a><br>
This displays simple text links with no formatting in a vertical format.
Now we need to put in the code so that we have a proper menu
For this we use a DIV tag to define the general CSS for the whole menu, and LI (List) tags for the individual formatting.
<ul>
<li><a href="#">Link1</a></li>
<li><a href="#">Link2</a></li>
<li><a href="#">Link3</a></li>
<li><a href="#">Link4</a></li>
<li><a href="#">Link5</a></li>
</ul>
</div>
This displays simple text links with no formatting in a vertical format.
Now for the CSS code
padding: 0px;
margin: 0px;
width: 150px;
}
The padding and margin make sure that the formatting stays the same and the width is optional. If the Menu is going within a table cell the width tag is not needed.
Remove padding and bullet point
padding: 0px;
margin: 0px;
list-style: none;
text-align: center;
}
The list-style: none; removes the bullet points, if you want the bullet points to stay, just remove this line.
Then we need to set out the LI tag so that the links appear right above each other:
border-top: 2px solid #E6E6E6;
}
This sets a border 2px big and fills it with #E6E6E6 rather than leaving a large gap, this has the same effect as a spacer would in a table.
Now we need to add the formatting to the actual links.
display: block;
background-colour: #F2F2F2;
color: #CCC;
text-decoration: none;
padding-left: 2px;
padding-right: 2px;
width: 100%;
border-left-style:solid;
border-left-color:#FFF;
border-left-width:3px;
border-right-style:solid;
border-right-color:#FFF;
border-right-width:3px;;
}
The display: block; is so that the background color takes up the whole of the "cell" rather than just covering the text.
The text-decoration; is so that the links won't be underlined.
The padding will keep the text 2px away from the left and right edges.
The border adds a border of 5px to both sides of the "cell".
Now we need to add the CSS for when the mouse hovers over the links.
text-decoration: none;
color: #000;
border-left-style:solid;
border-left-color:#0000FF;
border-left-width:3px;
border-right-style:solid;
border-right-color:#0000FF;
border-right-width:3px;
}
As you can see you don't need all the code fromt the normal link as it will cover all the link states anyway. From this code the left and right border change color and the text changes color too.
Click here to see the final result
Set up links for the navigation bar
Step 1
Code
<a href="#">Link1</a><br><a href="#">Link2</a><br>
<a href="#">Link3</a><br>
<a href="#">Link4</a><br>
<a href="#">Link5</a><br>
This displays simple text links with no formatting in a vertical format.
Now we need to put in the code so that we have a proper menu
Step 2
For this we use a DIV tag to define the general CSS for the whole menu, and LI (List) tags for the individual formatting.
Code
<div class="vertnav"><ul>
<li><a href="#">Link1</a></li>
<li><a href="#">Link2</a></li>
<li><a href="#">Link3</a></li>
<li><a href="#">Link4</a></li>
<li><a href="#">Link5</a></li>
</ul>
</div>
This displays simple text links with no formatting in a vertical format.
Now for the CSS code
Step 3
Code
.vertnav {padding: 0px;
margin: 0px;
width: 150px;
}
The padding and margin make sure that the formatting stays the same and the width is optional. If the Menu is going within a table cell the width tag is not needed.
Remove padding and bullet point
Step 4
Code
.vertnav ul {padding: 0px;
margin: 0px;
list-style: none;
text-align: center;
}
The list-style: none; removes the bullet points, if you want the bullet points to stay, just remove this line.
Then we need to set out the LI tag so that the links appear right above each other:
Code
.vertnav li {border-top: 2px solid #E6E6E6;
}
This sets a border 2px big and fills it with #E6E6E6 rather than leaving a large gap, this has the same effect as a spacer would in a table.
Now we need to add the formatting to the actual links.
Step 5
Code
.vertnav a {display: block;
background-colour: #F2F2F2;
color: #CCC;
text-decoration: none;
padding-left: 2px;
padding-right: 2px;
width: 100%;
border-left-style:solid;
border-left-color:#FFF;
border-left-width:3px;
border-right-style:solid;
border-right-color:#FFF;
border-right-width:3px;;
}
The display: block; is so that the background color takes up the whole of the "cell" rather than just covering the text.
The text-decoration; is so that the links won't be underlined.
The padding will keep the text 2px away from the left and right edges.
The border adds a border of 5px to both sides of the "cell".
Now we need to add the CSS for when the mouse hovers over the links.
Step 6
Code
.vertnav a:hover {text-decoration: none;
color: #000;
border-left-style:solid;
border-left-color:#0000FF;
border-left-width:3px;
border-right-style:solid;
border-right-color:#0000FF;
border-right-width:3px;
}
As you can see you don't need all the code fromt the normal link as it will cover all the link states anyway. From this code the left and right border change color and the text changes color too.
Rate This Tutorial
Comments
Add A comment










