Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you use HTML entities in the CSS “content” property? [duplicate]

Tags:

html

css

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.

like image 310
clamp Avatar asked Aug 30 '11 08:08

clamp


People also ask

Can you use HTML in CSS content?

Unfortunately, this is not possible. Per the spec: Generated content does not alter the document tree.

How do you add entities in HTML?

To add real spaces to your text, you can use the   character entity. Tip: The non-breaking hyphen (‑) is used to define a hyphen character (‑) that does not break into a new line.

What is the content property in CSS?

The content property in CSS is used to generate the content dynamically (during run time) ie., it replaces the element with generated content value. It is used to generate content ::before & ::after pseudo-element.

What is the:: before in HTML?

::before (:before) In CSS, ::before creates a pseudo-element that is the first child of the selected element. It is often used to add cosmetic content to an element with the content property. It is inline by default.


2 Answers

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

like image 113
sandeep Avatar answered Nov 05 '22 02:11

sandeep


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

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; } 
like image 45
twe4ked Avatar answered Nov 05 '22 01:11

twe4ked