This is the last part of our tutorial.We will add the favorite links on the left and link our styles in a separate CSS stylesheet.
Adding the XHTML code
First we will add the xhtml code for our favorite links:
My Favorite Sites
First we put all our links in a div container and give it an id name favlinks. This id is necessary to define width, margin and padding of the box containing our title and links through styles. Next we have our title between header tags. This will also be styled through css together with our list below it which also has a style defined. For the links we use a class style because this way we can use it repetitively in our page. So you could add another similar list of links with a header title. But if you do so make sure it is added in the "favlinks" container div or add another div id around these links to keep everything in the right place.
The CSS code
First we define our "favlinks" div id container:
#favlinks {width: 163px;padding-left: 15px;margin-top: 10px;}
We define the width of the box and give it a padding-leftso that it doesn't stick to the left. We also leave some extra space at the top and add some margin there. The width of our container is not 178px like our navigation, it is 163px since we added a left padding of 15px (163+15 makes 178). This is called the Box Model, also nicely presented in 3D by Jon Hicks.
#favlinks h2 {font: normal 16px Georgia, Times New Roman, Times, serif;color: #5C604D;margin: 0 0 10px 0;padding: 0;}
Next on the list are the styles for the header tag where we have our title. First 2 lines should be obvious by now, color and font styles. Below the padding and margin. We only added a 10px margin on the bottom. Padding and margins are needed for the header tags if we don't want to have very big gabs between the title and the links below, just some space exactly how we want it, and for me that is 10px at the bottom.
#favlinks ul {margin: 0;padding: 0;list-style-type: none;}
On to our next step in defining our listed links. First we make sure the standard bullet is hidden and that our margins and padding are set to zero, just like we did for the navigation in part 5.
ul.extlinks li {background: url(images/bullet_extlink.gif) no-repeat 0 3px;font: normal 11px/16px Verdana, Arial, Helvetica, sans-serif;padding-left: 12px;}
We've added a class called "extlinks" to define our links. We use "ul.extlinks li", which means that we style the li tag within the ul class "extlinks". First we add a non-repeated background, our bullet and we position it 3px from the top (y position) and 0px from the left (x position) to make sure the bullet aligns perfectly next to our links. We define the font style and then we add a left padding to make sure our text leaves some space on the left for our bullet.
.extlinks a:link {color: #A5003B;text-decoration: none;border-bottom: 1px dotted #A5003B;}
.extlinks a:visited {color: #6F2D47;text-decoration: none;border-bottom: 1px dotted #959E79;}
.extlinks a:hover {background-color: #C3C9B1;color: #A5003B;text-decoration: none;border-bottom: 1px solid #A5003B;}
And last but not least we define the colors and other styles for our links. We use a bottom border of 1 pixel which becomes solid when we roll over. To make sure we don't have a double border, we need to hide the standard underlining by adding "text-decoration: none". Font styles aren't necessary to add since they are already defined in the li tag style. We've also added a background color in the rollover state. We degraded the color a bit for the visited links and changed the bottom border with a subtile color, less visible. This way people know which links they've visited, things remain subtile and you can still make the difference. When adding these styles please make sure you that you are use the right order first links, then visited, hover and last active (if you want). There is a nice trick I learned from reading The Web Standards Solutions book by Dan Cederholm from Simple Bits, to makes sure you remember the correct order: LoVe /HAte (L from links, V from visited,...)
Here is the final result.
Creating the external stylesheet
Now that we have finished our design and I hear you yelling "Huray!" Just one more (important) thing (trying not to sound like Steve Jobs here...). You've noticed that I always include my styles within my webpage. But most of you will know this is not the right way to do this. You should put your styles in a separate stylesheet and link it to your document. I only did it this way to make things easier for you to learn because it's all there in 1 document. But like I said this is NOT the way. So we copy all our styles and paste them in a new document and save it as "styles.css".
Linking the stylesheet
This line of code is what we replace our old code with. Since this style sheet will be used to be displayed on a computer screen, we add media="screen". You could add another stylesheet by adding a link to another stylesheet and add media="print". This stylesheet will then be applied when people print your webpage. Very handy if you have a heavy colorful design on your screen and if you want to make sure when people print it it looks perfect on paper too. Other media types are also possible, more info can be found here.
Here is the final result with external stylesheet.
Now that our series are finished I'm really curious what you have done with the knowledge learned here. Don't hesitate to share what you've created in the comments. Hope you've enjoyed it.
from www.veerle.duoh.com
Before we start part 7 I want to correct a minor mistake of mine, mea culpa. When adding blocks of text I told you to put this between div tags but that is not semantically correct. It should be between paragraphs instead. This way everything still looks fine when the CSS stylesheet is dissabled. Doing so allows you to use top and bottom margins to adjust the vertical spacing between paragraphs. This way we also don’t need to use linebreak tags anymore. With this out of the way, bring on part 7. We will add a footer that sticks to the bottom of the browser window. I decided not to add the favorite links in this part yet because it would be too much. After all, this will be rather challenging and there is a lot to read too.