为什么要指定@charset"UTF-8";在您的CSS文件中? [英] Why specify @charset "UTF-8"; in your CSS file?

查看:334
本文介绍了为什么要指定@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.

这篇关于为什么要指定@charset"UTF-8";在您的CSS文件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆