In the first part of this tutorial, you learned how to design a modern header for a website using CSS. In this part of this step by step tutorial, you will find the instructions that teach how to create a modern navigation menu!
1. If you have not taken part one of this tutorial, you should consider going to take it now. Our current code looks like this:
| <html>
<head> <meta http-equiv="Content-Language" content="en-us"> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>My First CSS WebSite</title> <style type="text/css" media="all"> body { margin: 0; padding: 0; color: #000; background-color: #FFF; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 100%; } .header { background-color: #9A060B; color: #FFF; font-size: 24pt; font-weight: bold; padding: 5px; border-bottom: 1px solid #000; } .quote { width: 100%; background-color: #EEE; color: #000; font-size: 8pt; font-weight: bold; padding: 2px; border-bottom: 1px solid #000; text-align: right; } </style> </head> <body> <div class="header">CSS Website</div> <div class="quote">Because CSS is Awesome</div> </body> </html> |
2. Insert the following classes into your CSS Styles:
| table#main {
height: 100%; vertical-align: top; } table#main td { vertical-align: top; } td.leftnav { background: #9D4631; width: 175px; border-right: 1px solid #000; padding: 0px; color: #FFF; font-size: 10px; text-align: center; } td.leftnav div.header { background: #BD1219; color: #FFF; padding: 3px; border-bottom: 1px solid #000; font-size: 12px; font-weight: bold; text-align: center; } td.leftnav div.menu { background: #9B2E1B; padding: 0px; border-bottom: 1px solid #000; } td.leftnav div.menu a { display: block; padding: 2px; margin: 0px; font-size: 10px; color: #FFF; border-style:none; text-align: left; } td.leftnav div.menu a:hover { background: #C58873; color: #FFF; text-align: left; } |
3. The first class is the class that will effect our table we call "main". It will make the table expand to take up the entire height of the display. Our classes after this are all classes for our table cell that contains our left navigation (hence "leftnav"). We can apply this as follows:
|
<table cellspacing="0" id="main">
<tr> <td class="leftnav"> <div class="header">Menu 1</div> <div class="menu"> <a href="#">Link 1</a> <a href="#">Link 2</a> <a href="#">Link 3</a> <a href="#">Link 4</a> <a href="#">Link 5</a> </div> <div class="header">Menu 2</div> <div class="menu"> <a href="#">Link 1</a> <a href="#">Link 2</a> <a href="#">Link 3</a> <a href="#">Link 4</a> <a href="#">Link 5</a> </div> <div class="header">Menu 3</div> <div class="menu"> <a href="#">Link 1</a> <a href="#">Link 2</a> <a href="#">Link 3</a> <a href="#">Link 4</a> <a href="#">Link 5</a> </div> This is just a place where you can write some brief news, updates, and possibly insert some affiliates or links. You can even put more parts of your navigation menu here! </td> </tr> </table> |
4. We began by making a table, and calling it "main". We then created a new row (<tr>), and then a cell following the styles in "leftnav" class. After this cell was created we used "<div class="header">Menu 1</div>" so that it follows the style of the header class. So why doesn't this use the first header class we made? Because we are in the cell called "leftnav", we can create classes that can only be used in here. We did this in our classes by typing "td.leftnav div.header { style properties }". Our full code should now look like this:
|
<html>
<head> <meta http-equiv="Content-Language" content="en-us"> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>My First CSS WebSite</title> <style type="text/css" media="all"> body { margin: 0; padding: 0; color: #000; background-color: #FFF; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 100%; } .header { background-color: #9A060B; color: #FFF; font-size: 24pt; font-weight: bold; padding: 5px; border-bottom: 1px solid #000; } .quote { width: 100%; background-color: #EEE; color: #000; font-size: 8pt; font-weight: bold; padding: 2px; border-bottom: 1px solid #000; text-align: right; } table#main { height: 100%; vertical-align: top; } table#main td { vertical-align: top; } td.leftnav { background: #9D4631; width: 175px; border-right: 1px solid #000; padding: 0px; color: #FFF; font-size: 10px; text-align: center; } td.leftnav div.header { background: #BD1219; color: #FFF; padding: 3px; border-bottom: 1px solid #000; font-size: 12px; font-weight: bold; text-align: center; } td.leftnav div.menu { background: #9B2E1B; padding: 0px; border-bottom: 1px solid #000; } td.leftnav div.menu a { display: block; padding: 2px; margin: 0px; font-size: 10px; color: #FFF; border-style:none; text-align: left; } td.leftnav div.menu a:hover { background: #C58873; color: #FFF; text-align: left; } </style> </head> <body> <div class="header">CSS Website</div> <div class="quote">Because CSS is Awesome</div> <table cellspacing="0" id="main"> <tr> <td class="leftnav"> <div class="header">Menu 1</div> <div class="menu"> <a href="#">Link 1</a> <a href="#">Link 2</a> <a href="#">Link 3</a> <a href="#">Link 4</a> <a href="#">Link 5</a> </div> <div class="header">Menu 2</div> <div class="menu"> <a href="#">Link 1</a> <a href="#">Link 2</a> <a href="#">Link 3</a> <a href="#">Link 4</a> <a href="#">Link 5</a> </div> <div class="header">Menu 3</div> <div class="menu"> <a href="#">Link 1</a> <a href="#">Link 2</a> <a href="#">Link 3</a> <a href="#">Link 4</a> <a href="#">Link 5</a> </div> This is just a place where you can write some brief news, updates, and possibly insert some affiliates or links. You can even put more parts of your navigation menu here! </td> </tr> </table> </body> </html> |
5. Save, and open in your web browser. Your left navigation menu should now look like this:
You have now completed Part 2 of Designing a website with CSS.
Continue to part 3 to learn how to design the main content area of your website!








