Advertisements
Methods
Part One
The !DOCTYPE
Firstly and most importantly, make sure that you have the correct (X)HTML !DOCTYPE. Without this most browsers will be thrown into 'quirks' mode which will lead to all sorts of incompatibility problems. The has a list of valid DOCTYPES
that can be used. Select from XHTML1.0 or XHTML1.1 as these are more suitable for this styling. I use XHTML1.1 for all my current Web pages.
The (X)HTML for the basic unordered list is as below. This is a simple unordered list with no frills. The links would normally take you to another page giving information about each painter but I have used #nogo which will have no effect on this page.
|
1 | <ul> |
2 | <li><a href="#nogo">Paul C�zanne</a></li> |
3 | <li><a href="#nogo">Henri Matisse</a></li> |
4 | <li><a href="#nogo">William Turner</a></li> |
5 | <li><a href="#nogo">John Constable</a></li> |
6 | <li><a href="#nogo">Claude Monet</a></li> |
7 | </ul> |
|
|
The only change necessary to the above (X)HTML is to add a unique id to the <ul>
tag. This is done so that we can target the list with our CSS.
So the (X)HTML list becomes:
|
1 | <ul id="menu"> |
2 | <li><a href="#nogo">Paul C�zanne</a></li> |
3 | <li><a href="#nogo">Henri Matisse</a></li> |
4 | <li><a href="#nogo">William Turner</a></li> |
5 | <li><a href="#nogo">John Constable</a></li> |
6 | <li><a href="#nogo">Claude Monet</a></li> |
7 | </ul> |
|
|
Styling Part One
Step 1: Removing the Bullets
The first step is to style the unordered list to remove the bullets and the indentation.
Browsers have different ways of doing this; Internet Explorer and Opera use margin values for the indentation whereas Mozilla/Netscape/Firefox all use padding values, so to cater to this we need to style the list as follows:
|
1 | #menu { |
2 | padding:0; |
3 | margin:0; |
4 | } |
5 | #menu li { |
6 | list-style-type:none; |
7 | } |
|
|
padding:0;
- removes all padding from the unordered listmargin:0;
- removes all margins from the unordered listlist-style-type:none;
- removes the bullets
In the above example I have added a light grey background to the body and a white background to the unordered list so that you can see exactly what effect this styling has on the list.
The bullets are gone and the list is now left aligned with no indentation. The unordered list stretches the full width of the screen (the white background of the <ul>
tag is 100% by default).
Step 2: Styling the Link Width
The next step is to style the <a>
and the <a:visited>
tags which will be identical and can be grouped together.
Firstly, we will give the links a width just wide enough to hold the text in one line. In this case I have chosen to use em values for all sizes so that the menu will stay in shape when larger or smaller text sizes are chosen. It is also possible to use pixel or percentage values.
We can also add a border to each link just to show the size chosen:
|
1 | #menu a, #menu a:visited { |
2 | display:block; |
3 | width:9em; |
4 | border:1px solid #808; |
5 | } |
|
|
- display:block; - this will ensure that the link will be as wide as we specify. The height will be automatically set by the font size.
width:9em;
- sets the width of the links.border:1px solid #808;
- adds a 1 pixel wide solid purple border.
The list items now have a fixed width and are enclosed in purple boxes. The unordered list is still the full width of the screen.
Step 3: Styling the Link Font
We can now style the font used for the links:
|
1 | #menu a, #menu a:visited { |
2 | display:block; |
3 | width:9em; |
4 | border:1px solid #808; |
5 | font-family:arial, verdana, sans-serif; /* ADDED */ |
6 | font-size:0.8em; /* ADDED */ |
7 | text-align:center; /* ADDED */ |
8 | text-decoration:none; /* ADDED */ |
9 | } |
|
|
font-family:arial, verdana, sans-serif;
- we select arial as our first choice, followed by verdana. Lastly, we set the generic font to 'sans-serif'. A generic font should always be included as the last font in the list.font-size:0.8em;
- sets the font size slightly smaller than the default for the page. Using an em value allows your visitors to decide how big the font should be. You could choose pixel or point values.text-align:center;
- centers the text within the link box.text-decoration:none;
- removes the underline from the links.
Our text is now centered within the link box and we have lost the underline.