Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS - use character for list marker

Using CSS, how can I set a character like "►" as a list marker for an HTML list?

like image 254
Web_Designer Avatar asked Aug 09 '11 20:08

Web_Designer


People also ask

How do I style a marker in CSS?

The ::marker CSS pseudo-element selects the marker box of a list item, which typically contains a bullet or number. It works on any element or pseudo-element set to display: list-item , such as the <li> and <summary> elements.

Which CSS property is used to set the list item marker?

The list-style-type property specifies the type of list item marker.

Can we specify the style and position of the list item marker?

list-style-type: It is used to specify the type of list-item marker in a list. list-style-position: It is used to specify the position of the list-item markers.

Which CSS property would I use to change only the style of the list item marker for example from dot bullets to square bullets?

To create an unordered list with square bullets, we will use CSS list-style-type: square property. The list-style-type property in CSS specifies the appearance of the list item marker (such as a disc, character, or custom counter style).


2 Answers

Use the hex value of the desired character in CSS like this:

ul li:before { 
   content: "\25BA";  /* hex of your actual character, found using CharMap */
}

Note: this will not work in IE < 8

Demo: http://jsfiddle.net/mrchief/5yKBq/

To add a space after the bullet: content: "\25BA" " ";
Demo

You can also use an image like this:

ul {
   list-style: disc url(bullet.gif) inside;
}
like image 67
Mrchief Avatar answered Sep 18 '22 13:09

Mrchief


Also, if you need this in IE<8, you can use the following expression:

UL LI:before,
UL LI .before {
    content: "►"
    /* Other styles for this pseudo-element */
}

/* Expression for IE (use in conditional comments)*/
UL LI {
    list-style:none;
    behavior: expression(
        function(t){
            t.insertAdjacentHTML('afterBegin','<span class="before">►</span>');
            t.runtimeStyle.behavior = 'none';
        }(this)
    );
}
like image 45
kizu Avatar answered Sep 16 '22 13:09

kizu