我需要在CSS中包围字体家族名称的引号吗? [英] Do I need to wrap quotes around font family names in CSS?

查看:126
本文介绍了我需要在CSS中包围字体家族名称的引号吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我记得很久以前听说,被认为是最佳实践,在CSS font-family属性中包含包含多个单词的字体名称的引号,例如:

I remember hearing a long time ago that it was considered "best practice" to wrap quotes around font names that contain multiple words in the CSS font-family property, like this:

font-family: "Arial Narrow", Arial, Helvetica, sans-serif;

为此,我尝试删除 和Safari和Firefox没有任何问题呈现它。

For the heck of it, I tried removing the quotes from "Arial Narrow" and Safari and Firefox don't have any problem rendering it.

因此,有这个经验规则的任何逻辑,它只是一个神话?是旧版本的浏览器不再适用于当前版本的问题吗?

So, is there any logic to this rule of thumb, or is it just a myth? Was it an issue with older browsers that no longer applies to the current versions? I've been doing this for so long that I never stopped to think if it was actually necessary.

推荐答案

CSS 2.1规范告诉我们:


字体系列名称必须以字符串形式引用,或者以引号形式引用
作为一个或多个标识符的序列。这意味着每个标记开头的大多数标点符号
字符和数字必须在
无引号字体系列名称中转义。

Font family names must either be given quoted as strings, or unquoted as a sequence of one or more identifiers. This means most punctuation characters and digits at the start of each token must be escaped in unquoted font family names.

它继续说:


如果一个标识符序列被给定为字体系列名称,
value是通过以单个空格连接序列中的所有
标识符而转换为字符串的名称。

If a sequence of identifiers is given as a font family name, the computed value is the name converted to a string by joining all the identifiers in the sequence by single spaces.

为避免转义时出错,建议使用引号字体系列
包含空格,数字或标点符号的名称
除连字符之外:

To avoid mistakes in escaping, it is recommended to quote font family names that contain white space, digits, or punctuation characters other than hyphens:

,有一个区别,但不太可能导致任何问题。就个人而言,我总是在字体名称包含空格时引用。在几个(大概很罕见)的情况下,引号是绝对必需的:

So yes, there is a difference, but one that's unlikely to cause any problems. Personally, I have always quoted font names when they contain spaces. In a few (presumably very rare) cases, the quotes are absolutely required:


与关键字相同的字体名称值
('inherit','serif','sans-serif','monospace','fantasy'和
'cursive')必须引用以防止与
相同的名称。

Font family names that happen to be the same as a keyword value ('inherit', 'serif', 'sans-serif', 'monospace', 'fantasy', and 'cursive') must be quoted to prevent confusion with the keywords with the same names. The keywords 'initial' and 'default' are reserved for future use and must also be quoted when used as font names.



p>还要注意标点符号,如/或!在标识符中可能还需要引用或转义。

这篇关于我需要在CSS中包围字体家族名称的引号吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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