开发者社区> 问答> 正文

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

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

展开
收起
杨冬芳 2016-06-02 11:52:27 2872 0
1 条回答
写回答
取消 提交回答
  • IT从业

    首先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.

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

    2019-07-17 19:24:33
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
零基础CSS入门教程 立即下载
低代码开发师(初级)实战教程 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载