Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I include a HTML-encoded "content:" character in CSS? [duplicate]

Tags:

html

css

Possible Duplicate:
Adding HTML entities using CSS content

I have the following setup

CSS:

.header:before {
    content: "«";
}

.header:after {
    content: "»";
}

HTML:

<h3 class="header">Hello, this is some text which should be wrapped.</h3>

I'd simply like whatever is written in header to be wrapped in « (&laquo;) and » (&raquo;). How can I make this work in the CSS? It's currently appearing as:

&laquo; Hello, this is some text which should be wrapped. &raquo;

rather than:

« Hello, this is some text which should be wrapped. »

like image 438
Naftuli Kay Avatar asked Aug 18 '11 20:08

Naftuli Kay


People also ask

How do I add a Unicode character in CSS?

The general format for a Unicode character inside a string is \000000 to \FFFFFF – a backslash followed by six hexadecimal digits. You can leave out leading 0 digits when the Unicode character is the last character in the string or when you add a space after the Unicode character.

How do you add a copyright symbol in CSS?

CSS doesn't use HTML's entities; it uses its own unicode escape sequences. You need to use \00a9 for the copyright symbol.

Can you put text in CSS?

CSS can insert text content before or after an element.


1 Answers

You can't use HTML entities in CSS, but you can use Unicode hex escapes, such as

span.url:before { content: "\27e8" }
span.url:after { content: "\27e9" }

(from one of my own stylesheets -- look up the hex codepoints for the exact characters you want yourself). Notice that unlike in some other notations, hex digits follow the backslash directly, with no intervening u.

like image 77
hmakholm left over Monica Avatar answered Oct 21 '22 09:10

hmakholm left over Monica