![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjPP4hY7hdQPeEIpESFIq4SsO95DxUNINUwIuAx4RVc_yliArdqbK3vGf7KzsPeo4IGrkR9IJMJkrW8WzgnYT1Izz8IpcQfcExv2GnZRwbsWfqu3F0RWYAEgjLEGtDZVyUrFLURSvx_cKSo/s1600/use-character-entities-in-css-html-javascript.png)
For example, this usually looks good and when you click on this link, you should see the letters in the right way:
alert(" á é í ó ú ☺ ✛ ❤ ");If we are trying to use other method and we want to use this type of characters, sometimes we need to write them in a special format called escape sequence which is nothing but a backslash followed by a letter and a number in hexadecimal format. In the case of common characters or accents, it would be \x followed by two hex digits:
\xe1 is the letter áOther combinations generate special characters:
\xe9 is the letter é
\xed is the letter í
\xf3 is the letter ó
\xfa is the letter ú
\n is a line breakOr we can use \u followed by the Unicode character code expressed as four hexadecimal digits:
\t is the tab character
\' is single quote
\" is double quote
\\ is a back slash
\u00e1 is the letter áThis will allow us to see correctly what we couldn't before if we were using some other services:
\u00e9 is the letter é
\u00ed is the letter í
\u00f3 is the letter ó
\u00fa is the letter ú
alert(" \u263a \u2764 \u271b ");On this page you can find a comprehensive list of all the characters, both symbols and different alphabets.
Although rare characters are not often used in the CSS, there is a case when they are necessary as well, like when using the content property with the :after and :before pseudo-elements.
The same criteria applies there, but we only need to add a backslash followed by the four-digit hexadecimal code. For example:
content: ":\24d1\24d4\24d5\24de\24e1\24d4";
content: ":after \263a \2724 \2602";
:ⓑⓔⓕⓞⓡⓔ
:after ☺ ✤ ☂
Remember that IE doesn't understand the :before pseudoclass with content, and you would have to set the list-style-type property as none, or you would get 2 bullets in CSS compliant browsers.
0 nhận xét:
Đăng nhận xét