32

I would like to use HTML entities in CSS, but it shows me the • instead.

.down:before{ content:"• "; color:#f00; } 

Also, why does the above code not work in IE? it does not show the before part at all.

4
  • 2
    You want the user to see, on their screen, the • not the character? Commented Aug 30, 2011 at 8:27
  • i want the user to see the • and not the • stuff. stackoverflow converted my html entity ;) Commented Aug 30, 2011 at 8:30
  • 1
    Which version of IE? Psuedo-elements (:before, :after) aren't supported at all at 7 and under, and only partially in 8. Commented Aug 30, 2011 at 8:30
  • jsfiddle.net/Kyle_Sevenoaks/xRJmT looks fine here in Chrome. IE doesn't support the psuedo selector :before. Commented Aug 30, 2011 at 8:30

4 Answers 4

68

put hex value of your bullet specail character like this

div:before{ content:"\2022"; color:#f00; } 

check this fiddle http://jsfiddle.net/sandeep/HPrkU/1/

NOTE: after & before work in IE8

Sign up to request clarification or add additional context in comments.

4 Comments

excellent, thanks! about IE: it's probably another issue on my side then. that class is attached to a li element.
If :before is not working in IE8. Then check your doctype. Put this <!DOCTYPE html> in your html
... where "hex value" means "hexadecimal Unicode code point".
...and in case you have only those unicode symbols itself at hand / in your clipboard, or the decimal html entities or, or, or.... rishida r12a unicode converter is your greatest pal. (ever)
8

I'm guessing you want the actual character displayed, if so simply use the character instead of &bull;.

Example: http://jsfiddle.net/rmjt8/

Edit: I found another thread: How can I include a HTML-encoded "content:" character in CSS?

Perhaps this will validate:

.down:before{ content:"\2022 "; color:#f00; } 

10 Comments

i had that before, but then it doesnt validate.
Ahh sorry, I haven't validated my css in a while ;). As long as it's cross browser and my Sass generates I'm a happy camper.
@clamp: what validation error do you get? I pasted odin’s code into jigsaw.w3.org/css-validator/#validate_by_input, and it validated just fine.
i used utf-8 encoding and it said that dot is an invalid character.
@clamp: what said that the dot is an invalid character? The W3C’s CSS validator says it’s fine.
|
3

Assuming that you want the user to see the &bull; you can simply escape that sequence, to give:

.down:before{ content:"\&bull; "; color:#f00; } 

As to why it's not visible on IE7, that's because IE doesn't support generated content or the :before selector.

Edited to offer that, to see the actual bullet character, you should use:

.down:before{ content:"\2022"; color:#f00; } 

JS Fiddle demo.

1 Comment

nope sorry if my question was badly formulated, i want them to see the dot character. stackoverflow took the entity and converted it.
-1

You need to escape your entities:

.down:before{ content:"\&bull; "; color:#f00; } 

You cannot see it on IE because IE doesn't support :before (not :after)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.