CSS: Formatting a Definition ListWith the comeback of 'semantic markup' people are once again looking at what's the right tag to be using for different types of information. For example, unordered lists for navigation and tables only where absolutely necessary. One commonly overlooked option for markup of glossaries and definition lists is the dl attribute itself. The Definition List (DL)We know what the basic DL output looks like - not very attractive - which is why they are rarely used by webmasters. Here you can see an unformatted list with some sample content:
There are two options for adding some formatting. The first is to start adding HTML tags such as <b></b> for the 'data term' (dt) and maybe a smaller font size, or italics for the 'data definition' (dd). But we can do all that and more much better using CSS. Example 1Let's start with some simple CSS styles: dt {
font-weight: bold;
text-decoration: underline;
}
dd {
margin: 0;
padding: 0 0 0.5em 0;
}
Our simple list now looks a bit different. The indenting has been removed, some vertical padding inserted, and the data terms have been bolded and underlined:
That's a move in the right direction, but probably still not enough to convince people of the merits of this approach. The following example should prove more persuasive. Example 2In the first example we were just tinkering at the edges of what's possible using CSS. This example uses slightly more advanced code to further enhance the appearance of the list: dl {
border: 3px double #ccc;
padding: 0.5em;
}
dt {
float: left;
clear: left;
width: 100px;
text-align: right;
font-weight: bold;
color: green;
}
dt:after {
content: ":";
}
dd {
margin: 0 0 0 110px;
padding: 0 0 0.5em 0;
}
The list now appears as if the items were placed in a table:
Even the most sceptical webmaster should now be starting to re-think their position. Advantages of CSS formatting over HTMLSo why are we doing this again? There are a number of reasons:
It might take some time to 'clean up' your existing HTML code and convert lists and other elements to CSS but the advantages now and ongoing make it worthwhile. Feedback and Questions2006-01-11: Rafael says: Good example, but, did you try to print that page on Internet Explorer? Rafael, MSIE (Win) does have a problem printing this page but not I think with the formatted definition list. If you copy the example to one of your own pages and print I expect it will come out ok. |
|
|
© Copyright 2009 Chirp Internet
- Page Last Modified: 11 January 2006
|
|