tags:

views:

1672

answers:

4

I want to automatically add the html character » to the left of each li element

How I do that?

So I want to type the html

<ul>
  <li>item 1</li>
  <li>item 2</li>
  <li>item 3</li>
</ul>

and it displays

>> item 1
>> item 2
>> item 3
A: 

Use CSS :before Psuedo Element

li:before{
   content: "&raquo;&raquo;";
}

Most likely you also will want to add a little padding to the 'bullets', if so you can style the :before just like anything. So:

li:before{
   content: "&raquo;&raquo;";
   padding-right: 10px;
}

will intend the li 10px,

Also, check the comment below for a different value to put into the content: '' using hex code instead.

Chacha102
Keep in mind, this will not work in IE5/6/7. All other browsers support it correctly: http://www.quirksmode.org/css/contents.html If you need to support these other browsers, JavaScript will be required unless you add the character manually.
Dan Herbert
Brad
`:before` is a pseudo-element and not a pseudo-class. See http://www.w3.org/TR/CSS/selector.html#pseudo-elements
Gumbo
Jesse Kochis
@Gumbo Thanks, I'll change that
Chacha102
+6  A: 

I found the above answer didn't work for me, but the following does:

li:before{
   content: "\00BB";
}

This uses the hexadecimal code for &raquo instead.

A nice hexadecimal converter can be found here.

Hope this helps someone :)

brendo
+2  A: 

If you don't want the arrows to appear as content then why not go for a css background?

li { background: url("raquo.gif") no-repeat left center; }
I'd go with `{ list-style-image: url("raquo.gif") }` instead. It's specifically for this purpose and you avoid having to adjust the position of the content.
zinglon
A: