In this part of the tutorial we will be implementing our navigation on the left.
But first things first. When creating webpages we always have to make them as accessible as possible. If you read the comments on part part IV, you'll notice that someone mentioned it would be better to use a h1-element for the main header since this is more semantic code and it makes a site more accessible to search engines as well as people with no CSS. This is of course too important to overlook, so I've altered our code this way.
The image replacement technique
This technique is actually called the image replacement technique. It means that we use text in our HTML code instead of the actual image. The header image will show in browsers that support the CSS (as a background image "background: url(images/header.jpg)") and the text will be invisible (because of the "text-indent: -9999px"), since our CSS code places the text outside our viewing area. In older browsers or in screen readers (used by blind people) you'll see the text instead. This way we have more accessible code.
h1 {width: 692px;height: 90px;text-indent: -9999px;background: url(images/header.jpg);margin: 0;padding: 0;}
The width and height are necessary to define the space for our header background image. The "padding:0" and "margin:0" are needed to make sure our image aligns nicely to the top of our page. Furthermore, I've moved the "text-align: center" into our body tag selector since all the content should be centered. However, the content within the container should not be centered, so we add a "text-align: left" there. Our container has "margin: 0px auto" which means it will appear at the very top (0px) and centered (auto).
Implementing the navigation
To implement the navigation buttons on the left we first create an id container holding the content on the left:
#left {width: 178px;}
So far the only thing we need to define is its width. Within this left container we have the div id container for the navigation, called navcontainer. The best way to create a navigation with CSS is to use a bullet list as HTML code and create CSS styles to it to change its design. Like this ("#" is used as a dummy link. ):
This creates a simple bullet list. Since we don't want bullets but nice buttons instead, we will remove those bullets in our CSS and use background images instead. This is the CSS code:
#navcontainer {width: 178px;}
#navcontainer ul {margin: 0;padding: 0;list-style-type: none;font: bold 12px/22px Verdana, Arial, Helvetica, sans-serif;text-indent: 20px;letter-spacing: 1px;border-bottom: 1px solid #fff;}
The first piece of code defines the width of the navigation container. The second part defines the "ul" tag within the navcontainer. "margin:0" and "padding:0" makes sure there is no space between and around the buttons and it removes the left-indentation. "list-style-type: none;" removes the standard HTML bullet. Then we have the text specifications and the last one is there to create a white line at the bottom of our navigation to finish the navigation nicely.
#navcontainer a {display: block;width: 178px;height: 22px;}
#navcontainer a:link, #navcontainer a:visited {background: url(images/bg_navbutton.gif);color: #5C604D;text-decoration: none;}
#navcontainer a:hover {background: url(images/bg_navbutton_over.gif);color: #A5003B;text-decoration: none;}
The color sets the "color" of the text and the "text-decoration: none" is there to remove the standard underlining of a link.
It's always necessary to make your navigation as clear and simple as possible, so that's why I added an extra style to apply to the button of the current section. I've called it "current" and this is the CSS code:
#navcontainer li a#current {background: url(images/bg_navbutton_over.gif);color: #A5003B;text-decoration: none;}
This style defines the "current" id within the bullet link tag (li a) of the navcontainer. The properties and values listed are the same as our hover state. The only thing needed now is to add the current id to our HTML code:
A lot of good CSS navigation examples and tutorials can be found on:
- Listamatic, one list
- Listamatic 2, nested lists
- Listutorial, tutorial on CSS based lists
0 komentar:
Posting Komentar