Home >Web Front-end >Front-end Q&A >How to set encoding in css
In CSS, you can use the "@charset" rule for character encoding. You only need to set "@charset "Character Encoding"" at the top of the CSS file. The "@charset" rule specifies the character encoding used in the style sheet and must be the first element in the style sheet and cannot start with any character.
The operating environment of this tutorial: Windows 7 system, CSS3&&HTML5 version, Dell G3 computer.
At the top of the external css file, write the following code: @charset "UTF-8";
@charset CSS @Rule Specifies the character encoding used in the style sheet. It must be the first element in the stylesheet and must not be preceded by any characters. Because it is not a nested statement, it cannot be used in a @rule condition group. If multiple @charset @rules are declared, only the first one will be used, and it cannot be used within the style attribute within the HTML element or the character set-related c9ccee2e6ea535a969eb3f532ad9fe89 element of the HTML page.
This @rule is useful when using non-ASCII characters in certain CSS properties, such as content.
There are many ways to declare character encodings in style sheets. The browser will try the following methods in the following order (stopping and getting the result once found):
At the beginning of the file Unicode byte-order character value. The value given by the Content-Type: charset attribute in the HTTP header or the equivalent value in the protocol used to provide the style sheet. CSS @Rules @charset.
@charset "UTF-8"; @charset "utf-8"; /*大小写不敏感*/ /* 设置css的编码格式为Unicode UTF-8 */ @charset 'iso-8859-15'; /* 无效的, 使用了错误的引号 */ @charset 'UTF-8'; /* 无效的, 使用了错误的引号 */ @charset "UTF-8"; /* 无效的, 多于一个空格 */ @charset "UTF-8"; /* 无效的, 在at-rule之前多了一个空格 */ @charset UTF-8; /* Invalid, without ' or ", the charset is not a CSS <string> */
Recommended learning: css video tutorial
The above is the detailed content of How to set encoding in css. For more information, please follow other related articles on the PHP Chinese website!