首页 > CSS里font-family 属性的值区分大小写字母吗

CSS里font-family 属性的值区分大小写字母吗

Microsoft Yahei 和 Microsoft YaHei 看起来好像是一样的


首先CSS2.1 font这一章没有提及font-family的大小写问题,只提到它的值要么作为标志符出现、要么作为string出现。

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.

在CSS2.1里定义的字体匹配算法里也没有提到。

我们专门找到string格式定义的这一章:

All CSS syntax is case-insensitive within the ASCII range (i.e., [a-z] and [A-Z] are equivalent), except for parts that are not under the control of CSS. For example, the case-sensitivity of values of the HTML attributes "id" and "class", of font names, and of URIs lies outside the scope of this specification. Note in particular that element names are case-insensitive in HTML, but case-sensitive in XML.

原来找了这么半天已经超出CSS的定义范围了吗。

不,其实CSS3的字体匹配算法里已经重新定义了字体匹配过程:

Case sensitivity of font family names
As part of the font matching algorithm outlined below, user agents must match font family names used in style rules with actual font family names contained in fonts available in a given environment or with font family names defined in @font-face rules. User agents must match these names case insensitively, using the "Default Caseless Matching" algorithm outlined in the Unicode specification [UNICODE]. This algorithm is detailed in section 3.13 entitled "Default Case Algorithms". Specifically, the algorithm must be applied without normalizing the strings involved and without applying any language-specific tailorings. The case folding method specified by this algorithm uses the case mappings with status field ‘C’ or ‘F’ in the CaseFolding.txt file of the Unicode Character Database.

所以对于现代浏览器来说,字体匹配过程是不区分大小写的。


http://www.w3.org/html/ig/zh/wiki/CSS3%E5%AD%97%E4%BD%93%E6%A8%A1%E5%9... 中也有说 对于名字匹配是不区分大小写的。

【热门文章】
【热门文章】