Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change bullets color of an HTML list without using span

Tags:

html

css

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?

like image 846
Kim Andersen Avatar asked Sep 24 '09 07:09

Kim Andersen


People also ask

Can you change the color of bullets in HTML?

Note: We cannot change the color of the bullet of the unordered list by default but we can take the help of some other tags and selectors. There are two ways to change the color of the bullet: Using an extra markup tag. Using Css style ::before selector.

Can we change bullets of an HTML list?

The default bullets can be replaced with other native options or completely removed using CSS to manipulate the list-style-type property. You can even change the UL bullet to a custom image or icon.


1 Answers

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.

li {    list-style: none;  }  li:before {    /* For a round bullet */    content: '\2022';    /* For a square bullet */    /*content:'\25A0';*/    display: block;    position: relative;    max-width: 0;    max-height: 0;    left: -10px;    top: 0;    color: green;    font-size: 20px;  }
<ul>    <li>foo</li>    <li>bar</li>  </ul>
like image 140
Marc Avatar answered Oct 20 '22 16:10

Marc