Home  >  Article  >  Web Front-end  >  How to set css file to utf-8

How to set css file to utf-8

青灯夜游
青灯夜游Original
2022-01-20 18:43:194390browse

In CSS, you can use the "@charset" rule to set the character encoding to "utf-8". This rule can specify the character encoding used in the style file. The syntax is "@charset "UTF-8" ";" The "@charset" rule must be the first element in the stylesheet and must not be preceded by any characters.

How to set css file to utf-8

The operating environment of this tutorial: Windows 7 system, CSS3&&HTML5 version, Dell G3 computer.

In CSS, you can use the "@charset" rule to set the character encoding to "utf-8".

@charset attribute specifies the character encoding used in style files (.css suffix) and can only be used in CSS files.

It must be the first element in the style sheet, and there must be no characters in front of it, not even comments.

If multiple @charset rules are declared, only the first one will be used, and it cannot be used in HTML elements or HTML pages, that is, it cannot be used within the c9ccee2e6ea535a969eb3f532ad9fe89 element.

Note: @charset rules cannot be used in the character set-related c9ccee2e6ea535a969eb3f532ad9fe89 elements of HTML pages.

After "@charset", specify the name of the character encoding (in quotation marks), The syntax is:

@charset "字符集名";

Indicates that the character set name is a distinction case, but for new stylesheets it should always be UTF-8. It must be the name of a web-safe character encoding defined in the IANA registry.

Example 1: The following @charset declaration indicates that the style sheet uses UTF-8 character encoding:

@charset "UTF-8";

Example 2: The following list describes Wrong character set encoding:

@charset 'iso-8859-15'; /* 使用了错误的引用样式,因此它无效*/
@charset  UTF-8;   /* 无效,因为字符编码名称未包含在引号中*/
@charset  "UTF-8"; /*多个空格无效 */
 @charset "UTF-8";/* 无效,在规则之前有一个字符(空格)*/

Description: If a special character used in a style sheet cannot be represented in the character encoding specified in the style sheet, you can use "Character Escape" to escape the character.

(Learning video sharing: css video tutorial)

The above is the detailed content of How to set css file to utf-8. 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