XML technologies / CSS / CSS Cookbook / Lists / Enhancing a list with graphics
(Excerpt from “CSS Kochbuch” by Christopher Schmitt)
Problem
Use graphics to draw users’ attention to a list.
Solution
Use custom graphics for the background of the element ul and the markers of elements li.
First create a background image for the unordered list and an image for the marker (see the following figure).
Figure: The images used in the design.
Next, define the background image for the element ul. To give the list the same width as the image, also use the property width (see the next figure):
ul {
background: url(list-bkgd.gif) bottom;
width: 298px;
list-style: none;
padding: 0 0 12px;
margin: 0;
}Figure: The background image for the entire list.
Now define the list items’ markers. Border definitions can also separate the items more clearly (see the following figure):
ul {
background: url(list-bkgd.gif) bottom;
width: 298px;
list-style: none;
padding: 0 0 12px;
margin: 0;
}
li {
color: #eee;
font-family: Verdana, Arial, Verdana, sans-serif;
padding: 7px 7px 7px 20px;
border-bottom: 1px solid #888;
background: url(list-marker.gif) no-repeat 5px .8em;
}Figure: List item styles complete the design.
Discussion
This solution combines several techniques. The first is a custom background image for the element ul. Since this graphic has a fixed height and width, define the list’s width in CSS too.
Developers may hesitate to use the property height for several reasons: users might change the default text size, or the styles might be applied to lists with very many or very few items.
To work in as many situations as possible, the background image must be very tall. Our example uses a 465-pixel-high image, more than enough for a handful of items. As the next figure shows, the design remains intact even with much larger text.
Figure: The design survives large text sizes.
Since the background has rounded bottom corners, a 12-pixel bottom margin keeps list items out of that area. The background position is also set to bottom so the rounded corners remain visible when text is enlarged or more items are added.
The items also combine several techniques. First, they are visually separated. Unlike the recipe Separating list items, this solution defines no bottom border for the element ul. Second, we use the technique from the recipe Using large graphics as markers to define custom markers.
See also
The section Links and navigation describes ways to display a list as a navigation menu.
Copyright of the German edition © 2007 by O’Reilly Verlag GmbH & Co. KG
You may print the online version for your private use.
Otherwise, this chapter from “CSS Kochbuch” is subject to the same conditions as the bound edition: the work, including all its parts, is protected by copyright. All rights reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
O’Reilly Verlag GmbH & Co. KG, Balthasarstr. 81, 50670 Köln