Reputation: 195
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?
Upvotes: 18
Views: 77478
Reputation: 311
this did the trick for me:
ul li{
color: var(--color-text);
}
li::marker{
list-style: disc;
color: var(--color-blue);
}
instead of predefined vars you can enter the color code.
Upvotes: 1
Reputation: 47
li::marker {
color: #61dafb; //To change the color of bullet
font-size: 2rem; //To change the size of the bullet
}
https://developer.mozilla.org/en-US/docs/Web/CSS/::marker
Upvotes: 2
Reputation: 201
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.
Upvotes: 3
Reputation: 101
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!
Upvotes: 10
Reputation: 723729
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;
}
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;
}
Upvotes: 47
Reputation: 6260
You can create your own image.
li {
list-style-image: url(myImage.gif);
}
Upvotes: 2
Reputation: 15159
I think you have to use a graphic:
http://catcode.com/csstips/graphic_list.html
As an aside, this will also give you granular control over the bullet positioning (by using margins and image offset).
Upvotes: 0