【发布时间】:2016-07-21 09:05:07
【问题描述】:
短版
为什么two sections here 的呈现方式不同,尽管它们都具有与font-family: css 属性中的第一项相同的available字体?
超长版:
As far as as I know,在 css 中,'font-family' 属性包含一个字体列表,从左到右优先级。如果找到第一个字体,则列表中的其他字体无关紧要:
属性值是字体系列名称的优先列表和/或 通用姓氏。 w3.org
和
font-family 属性可以保存多个字体名称作为“后备” 系统。如果浏览器不支持第一种字体,它会尝试 下一个字体。 w3schools.com
所以,我有以下一段 html,重复了两次,一次在 #font-simple-stack 内,另一次在 #font-full-stack div 内:
<h1 class="serif">
<abbr title="EtaBits">ηBits</abbr> Syria</span>
<small> Web Development & Solutions</small>
</h1>
<p class="sans-serif"><strong>EtaBits</strong> is your ultimate online business partner, it helps your business whether it is internet-based or internet-promoted.</p>
<p class="sans-serif"><strong>EtaBits</strong> is a Syria based Web Consultancy, Development & Solutions firm. We aim at providing you with exactly what you need to reach your users and clients.</p>
...以及以下字体 css 定义:
#font-simple-stack .serif {
font-family: 'Roboto Slab', serif;
}
#font-simple-stack .sans-serif {
font-family: 'Open Sans', sans-serif;
}
#font-full-stack .serif {
font-family: 'Roboto Slab', "Palatino Linotype", Palatino, Palladio, "URW Palladio L", "Book Antiqua", Baskerville, "Bookman Old Style", "Bitstream Charter", "Nimbus Roman No9 L", Garamond, "Apple Garamond", "ITC Garamond Narrow", "New Century Schoolbook", "Century Schoolbook", "Century Schoolbook L", Georgia, serif;
}
#font-full-stack .sans-serif {
font-family: 'Open Sans', "Segoe UI", Candara, "Bitstream Vera Sans", "DejaVu Sans", "Bitstream Vera Sans", "Trebuchet MS", Verdana, "Verdana Ref", sans-serif;
}
Roboto Slab 和 Open Sans 这两个类别中的第一个字体都是从 google fonts api 加载的:
<link type="text/css" rel="stylesheet" href="http://fonts.googleapis.com/css?family=Roboto+Slab:600|Open+Sans:400,700" />
所有人都说,我希望在这两种情况下,无论是在 #font-full-stack 还是 #font-simple-stack 内,都会产生相同的结果,但实际上,the two stacks renders differently!
我在 Ubuntu 12.04 x64 机器上测试了 Firefox 和 Chromium。
【问题讨论】:
-
当您在第二个示例中列出较少的字体时会发生什么?比如
'Roboto Slab', Palatino, Helvetica?可能与此有关,或者其中一个字体名称存在拼写错误。 -
@AlexLynham 即使有拼写错误,浏览器也应该将其视为不存在的字体。只要找到第一个字体 (
Roboto Slab),它就不应该尝试检查其他字体。尝试删除一两个字体可能会解决问题,但我更感兴趣的是找到问题的根源。 -
啊,很公平。也有兴趣了解根本原因!
标签: html css fonts cross-browser font-family