为什么要指定@charset"UTF-8";在您的CSS文件中?

问题描述:

我一直将此指令视为移交给我的众多CSS文件的第一行:

I've been seeing this instruction as the very first line of numerous CSS files that have been turned over to me:

@charset "UTF-8";

它是做什么的,这是必要的规则吗?

What does it do, and is this at-rule necessary?

此外,如果我在"head"元素中包含此元标记,是否将不需要在CSS文件中也包含该元标记?

Also, if I include this meta tag in my "head" element, would that eliminate the need to have it also present within my CSS files?

<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">

它告诉浏览器以UTF-8格式读取css文件.如果您的CSS包含Unicode字符,而不仅仅是ASCII,则非常方便.

It tells the browser to read the css file as UTF-8. This is handy if your CSS contains unicode characters and not only ASCII.

在meta标签中使用它很好,但仅适用于包含该meta标签的页面.

Using it in the meta tag is fine, but only for pages that include that meta tag.

w3c规范中了解CSS文件的字符集解析规则./a>用于CSS 2.

Read about the rules for character set resolution of CSS files at the w3c spec for CSS 2.