Placing Unicode character in CSS content value

This question already has an answer here:

  • Adding HTML entities using CSS content 9 answers

  • Why don't you just save/serve the CSS file as UTF-8?

    nav a:hover:after {
        content: "↓";
    }
    

    If that's not good enough, and you want to keep it all-ASCII:

    nav a:hover:after {
        content: "2193";
    }
    

    The general format for a Unicode character inside a string is 00000 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. See the spec below for full details.


    Relevant part of the CSS2 spec:

    Third, backslash escapes allow authors to refer to characters they cannot easily put in a document. In this case, the backslash is followed by at most six hexadecimal digits (0..9A..F), which stand for the ISO 10646 ([ISO10646]) character with that number, which must not be zero. (It is undefined in CSS 2.1 what happens if a style sheet does contain a character with Unicode codepoint zero.) If a character in the range [0-9a-fA-F] follows the hexadecimal number, the end of the number needs to be made clear. There are two ways to do that:

  • with a space (or other white space character): "26 B" ("&B"). In this case, user agents should treat a "CR/LF" pair (U+000D/U+000A) as a single white space character.
  • by providing exactly 6 hexadecimal digits: "00026B" ("&B")
  • In fact, these two methods may be combined. Only one white space character is ignored after a hexadecimal escape. Note that this means that a "real" space after the escape sequence must be doubled.

    If the number is outside the range allowed by Unicode (eg, "110000" is above the maximum 10FFFF allowed in current Unicode), the UA may replace the escape with the "replacement character" (U+FFFD). If the character is to be displayed, the UA should show a visible symbol, such as a "missing character" glyph (cf. 15.2, point 5).

  • Note: Backslash escapes are always considered to be part of an identifier or a string (ie, "7B" is not punctuation, even though "{" is, and "32" is allowed at the start of a class name, even though "2" is not).
    The identifier "test" is exactly the same identifier as "test".

  • Comprehensive list: Unicode Character 'DOWNWARDS ARROW' (U+2193).

    链接地址: http://www.djcxy.com/p/15528.html

    上一篇: nbsp在CSS内容标签中不起作用

    下一篇: 将Unicode字符放在CSS内容值中