XML technologies / CSS / CSS Cookbook / Lists / Separating list items
(Excerpt from “CSS Kochbuch” by Christopher Schmitt)
Problem
List items should be visually separated from one another.
Solution
First use the property border-top to create a partial border above each list item (li) to serve as a separator:
li {
border-top: 1px solid black;
padding: .3em 0;
}To display a separator below the last item as well, give the list itself (li) a partial bottom border using the property border-bottom (see the next figure):
ul {
margin-left: 40px;
padding-left: 0px;
border-bottom: 1px solid black;
list-style: none;
width: 36%;
}Figure: List items are visually separated.
Discussion
To give the separators between items the correct length, assign an appropriate value to either margin-left or padding-left for the unordered list. Otherwise, the borders for the list items and the list itself will have different lengths. For example, if the list items are indented using padding-left, the bottom border (for the list itself) will be longer than the borders for the individual items (see the next figure):
li {
border-top: 1px solid black;
padding: .3em 0;
}
ul {
margin-left: 0px;
padding-left: 40px;
border-bottom: 1px solid black;
list-style: none;
width: 36%;
}Figure: The list’s bottom border is longer than the borders of its individual items.
See also
The recipe Cross-browser indentation for creating list indentation that works across browsers.
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