Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change the color of the dot in an unordered list?

Tags:

html

css

I want to change the color of dots in an unordered list:

<ul>
<li></li>
</ul>

Is there a way that I can do this with CSS? I can't see a property?

like image 994
Marie Avatar asked Apr 30 '11 04:04

Marie


3 Answers

The easiest (but rather unsemantic) way is to wrap the content in span tags, then apply the bullet color to li and text color to span.

In code:

<ul>
    <li><span>text</span></li>
    <li><span>text</span></li>
    <li><span>text</span></li>
</ul>
ul li {
    /* Bullet color */
    color: red;
    list-style-type: disc;
}

ul li span {
    /* Text color */
    color: black;
}

jsFiddle preview

If you can't modify your HTML, you can either use list-style-image with a custom-colored dot, or use generated content (i.e. li:before) and color it accordingly (but watch out for list bullet position problems).

Here's an example with li:before:

ul li {
    /* Text color */
    color: black;
    list-style-type: none;
}

ul li:before {
    /* Unicode bullet symbol */
    content: '\2022 ';
    /* Bullet color */
    color: red;
    padding-right: 0.5em;
}
like image 189
BoltClock Avatar answered Oct 14 '22 07:10

BoltClock


Further developing the answer given by @BoltClock:

ul li {
    color: black;
    list-style-type: none;
}

ul li:before {
    color: red;
    float: left;
    margin: 0 0 0 -1em;
    width: 1em;
    content: '\2022';
}

In this way all lines of a multi-line bullet are indented properly. Beware: I’ve not had the chance to test it on IE yet!

like image 25
ranbureand Avatar answered Oct 14 '22 08:10

ranbureand


None of the above answers work for me, as I had content that wrapped onto multiple lines. However the solution provided by W3C is perfect: https://www.w3.org/Style/Examples/007/color-bullets.en.html

In short, remove styling:

ul {list-style: none}

Then add your own bullet

li::before {
content: "•";
color: red;
display: inline-block;
width: 1em;
margin-left: -1em
}

The key points are inline-block, width and margin to position it correctly.

like image 44
GGG Avatar answered Oct 14 '22 07:10

GGG