Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

– encoding of em dash when inserted using CSS :after

I'm getting the old – on my page when I try to render an em dash ( ). This can be cleared up by adding <meta charset="utf-8"> to the document head, I believe. But in this case I'm inserting the em dash via css.

.el:after{
   content: "— content to be after";
}

Somehow it is not being encoded properly. content: "&mdash;"; does not work either; it only renders the amersand code. How can I solve this?

like image 797
1252748 Avatar asked Sep 26 '13 21:09

1252748


People also ask

How do I encode an em dash?

Word automatically converts the hyphen to an en dash. Html codes for the em dash are &mdash; or &#8212; To produce an em dash in Word, press Ctrl-Alt-minus sign on the numeric keypad. Or press the Alt key while typing 0151 on the numeric keypad.

Is em dash a UTF 8 character?

"End of guarded area" encoded in utf-8 is the two-byte sequence: 0xC2 0x97. The text file was correctly interpreted as w-1252, thus the 0x97 is recognized as em dash, which was correctly encoded as the em dash in utf-8: 0xE2 0x80 0x94.

How do you insert a dash in HTML?

If you work with web pages, create an en dash in HTML by typing "–" or "–." You can also use the Unicode numeric entity of U+2013.


2 Answers

While setting the correct encoding is always a good thing to do, I try to avoid this situation entirely and use only ASCII characters in HTML, JavaScript and CSS:

content:"\2014"

Unicode characters are represented by \hexValue in CSS.

Beware that if the following character is 0-9 or a-f (or A-F), it will be considered part of the unicode character. You can put a space after it: "\2014 stuff", and the space won't be displayed (it just marks the end of the character). To actually put a space after it, use two spaces.

like image 109
Dave Avatar answered Sep 22 '22 18:09

Dave


Try adding the following on top of your stylesheet

@charset "UTF-8";

Your HTTP server (Apache, Nginx, etc) probably is specifying a different charset. It should be responding with:

Content-Type: text/css; charset=UTF-8

For for info see http://www.w3.org/

like image 45
Arnold Daniels Avatar answered Sep 19 '22 18:09

Arnold Daniels