XML technologies / CSS / CSS Cookbook / Lists / Using large graphics as list markers

(Excerpt from “CSS Kochbuch” by Christopher Schmitt)

Problem

If you use particularly large graphics for the property list-style-image, they may not be displayed in full.

Solution

Instead of list-style-image, use the property background. First remove the default list marker using the property list-style (see the next figure):

ul {
 margin-left: 40px;
 padding-left: 0px;
 list-style: none;
}

Default list markers have been removed

Figure: The default list markers have been removed.

To leave enough room for the new image, define a sufficiently wide left margin for the list items (see the following figure):

ul {
 margin-left: 40px;
 padding-left: 0px;
 list-style: none;
}
li {
 padding: .3em 0 1em 40px;
 font: 1.1em/1.2 Verdana, Arial, Verdana, sans-serif;
}

Additional margin has been defined to the left of the list items

Figure: Additional margin has been defined to the left of the list items.

Now insert the new list marker using the property background (see the next figure):

ul {
 margin-left: 40px;
 padding-left: 0px;
 list-style: none;
}
li {
 padding: .3em 0 1em 40px;
 font: 1.1em/1.2 Verdana, Arial, Verdana, sans-serif;
 background: url(search_32.eps) no-repeat;
}

List markers are displayed in full

Figure: List markers are displayed in full.

Discussion

Using the property background gives you more design freedom than list-style-image. With this technique, list markers can be any size, provided that the left margin is wide enough.

See also

The recipe Enhancing a list’s appearance with graphics for a more complex version of this solution.

  

 

 

 

back to top