我需要在CSS中包围字体家族名称的引号吗?

前端之家收集整理的这篇文章主要介绍了我需要在CSS中包围字体家族名称的引号吗?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我记得很久以前听说,被认为是“最佳实践”,在CSS font-family属性中包含包含多个单词的字体名称,例如:
font-family: "Arial Narrow",Arial,Helvetica,sans-serif;

对于它的,我试图删除“Arial Narrow”的报价,Safari和Firefox没有任何问题呈现它。

那么,这个经验法则有什么逻辑,还是只是一个神话?是旧版本的浏览器不再适用于当前版本的问题吗?我一直这样做这么久,我从来没有停止思考,如果它实际上是必要的。

解决方法

CSS 2.1 spec告诉我们:

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.

它继续说:

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:

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

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.

还要注意标点符号,如/或!在要引用或转义的标识符may also need内。

原文链接:https://www.f2er.com/css/223645.html

猜你在找的CSS相关文章