Home  >  Article  >  Web Front-end  >  How to set encoding in css

How to set encoding in css

醉折花枝作酒筹
醉折花枝作酒筹Original
2021-04-21 16:17:163149browse

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.

How to set encoding in css

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 &#39; 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn