I would like to use an icon from the jQuery UI icon set to style an unordered list.
<div>
<ul>
<li>John Doe</li>
<li>Jack Snow</li>
<li>Mary Moe</li>
</ul>
</div>
By default this list appears with dots in front of each element:
- John Doe
- Jack Snow
- Mary Moe
Instead I would like to replace the dot with an icon such as ui-icon-person
How to accomplish this?
You may need to add some left padding as well.
Looking at the source for the page, just set the class file of the list item to clear the standard element, and then set a span tag to add the new icon.
I know this question is a little out-of-date - but here is a fully working example:
HTML:
CSS:
Here is a jsFiddle showing it working. The result will look something like this:
The reason that I used the
:before
pseudo-element is that you are wanting to use jQuery-UI icons - which come in the form of a sprite map. In other words - all of the icons are found in a grid pattern within a single image, as in this example:Source: http://download.jqueryui.com/themeroller/images/ui-icons_888888_256x240.png
If you tried to just make the background of the
<li>
that image, it would be more complicated to make the single icon that you want appear without also displaying all of its neighbors. By using the:before
element, though, you can create a smaller,16px
by16px
box for the icon, and thereby easily trim down to showing only one icon.If you want to learn more about
:before
and:after
pseudo-elements, check out this fantastic article as a starting point.