I was wondering if there is a way to change the color on the bullets in a list.
I have a list like this:
<ul>
<li>House</li>
<li>Car</li>
<li>Garden</li>
</ul>
It is not possible for me to insert anything in the li's such as a 'span' og a 'p'. So can I change the color of the bullets but not the text in some smart way?
Building off @Marc's solution -- since the bullet character is rendered differently with different fonts and browsers, I used the following css3 technique with border-radius to make a bullet that I have more control over:
For me the best option is to use CSS pseudo elements, so for
disc
bullet styling it would look like that:Notes:
width
andheight
should have equal values to keep pointers roundedborder-radius
to zero if you want to havesquare
list bulletsFor more bullets styles you may use other css shapes https://css-tricks.com/examples/ShapesOfCSS/ (choose this which doesn't require pseudo elements to work, so for example triangles)
If you can use an image then you can do this. And without an image you won't be able to change the color of the bullets only and not the text.
Using an image
See
list-style-image
Without using an image
Then you have to edit the HTML markup and include a span inside the list and color the li and span with different colors.
I really liked Marc's answer too - I needed a set of different colored ULs and obviously it would be easier just to use a class. Here is what I used for orange, for example:
Plus, I found that the hex code I used for "content:" was different than Marc's (that hex circle seemed to sit a bit too high). The one I used seems to sit perfectly in the middle. I also found several other shapes (squares, triangles, circles, etc.) right here
Building on @ddilsaver's answer. I wanted to be able to use a sprite for the bullet. This appears to work:
I managed this without adding markup, but instead using
li:before
. This obviously has all the limitations of:before
(no old IE support), but it seems to work with IE8, Firefox and Chrome after some very limited testing. The bullet style is also limited by what's in unicode.