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?
We can combine
list-style-image
withsvg
s, which we can inline in css! This method offers incredible control over the "bullets", which can become anything.To get a red circle, just use the following css:
But this is just the beginning. This allows us to do any crazy thing we want with those bullets. circles or rectangles are easy, but anything you can draw with
svg
you can stick in there! Check out the bullseye example below:Width/height attributes
Some browsers require
width
andheight
attributes to be set on the<svg>
, or they display nothing. At time of writing, recent versions of Firefox exhibit this problem. I've set both attributes in the examples.Encodings
A recent comment reminded me of encodings for the data-uri. This was a pain-point for me recently, and I can share a bit of information I've researched.
The data-uri spec, which references the URI spec, says that the svg should be encoded according to the URI spec. That means all sorts of characters should be encoded, eg
<
becomes%3C
.Some sources suggest base64 encoding, which should fix encoding issues, however it will unnecessarily increase the size of the SVG, whereas URI encoding will not. I recommend URI encoding.
More info:
browser-support: >ie8
css tricks on svgs
mdn on svgs
I know this is a really, really, old question but i was playing around with this and came up with a way i have not seen posted. Give the list a color and then overwrite the text color using
::first-line
selector. I'm no expert so maybe there is something wrong with this approach that I'm missing, but it seems to work.Building off both @Marc and @jessica solutions - This is the solution that I use:
I use
em
for font sizes so if you set yourtop
value to be.5em
it will always be placed to the mid point of your first line of text. I usedleft:-20px
because that is the default position of bullets in browsers: parentpadding/2
I tried this today and typed this:
I needed to display color markers in my lists (both bullets and numbers). I came upon this tip and wrote in in my stylesheet whith mutualization of the properties:
I chose a different character to display a bullet, watching it here. I needed to adjust the margin accoardingly, maybe the values won't apply with the font you chose (the numbers use your webfont).