是否可以强制“字体优先”?在样式表中?
在各种浏览器中,当使用特定字体(例如 - Helvetica Neue)时,如果找不到该字体,则使用直系字体中的第一个字体。因此,如果我指定 Arial Narrow 是某个元素的基本字体样式,而我的读者没有这种字体,那么它将转到系统可以找到的第一个可用的 Arial 字体。
作为练习,许多网站都喜欢 Helvetica 字体(特别是“Neue”和“Condensed”版本)。他们通常指定 font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
相信浏览器将沿着这个特定的路径移动,并且每种字体都应该是美味的,其中第一个列出的字体是最美味的。然而,Firefox/IE/Chrome(所以我假设是 webkit 浏览器)都将无法找到所需的特定 Helvetica 字体,并直接移动到它们在 Helvetica 家族中遇到的第一个字体。人们可能会认为这是 Helvetica,但在我的系统上它默认为 Helvetica 95 Black。我什至尝试重命名字体文件,看看这是否是原因,无论文件名如何,结果都是页面默认为 Helvetica Black。我发现 Arial 也是如此。
那么,除了试图解释 Helvetica、Arial、Verdana、Tahoma 的每一种风格,无穷无尽之外,是否有办法强制浏览器停止“猜测”系列并只接受有问题的确切字体?
In various browsers, when a specific font is used (e.g. - Helvetica Neue), if that font is not found, the first font in the immediate family is used. So if I were to specify that Arial Narrow was the base font style for an element and my reader did not have this font, it would travel to the first available Arial font the system could find.
As an exercise, many sites like the Helvetica fonts (particularly the 'Neue' and 'Condensed' versions). They typically specify font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
believing that the browser will travel along this particular path and each font should be yummy with the first listed being the yummiest. However, Firefox/IE/Chrome (so I assume webkit browsers) all will fail to the find the specific Helvetica font required and move directly to the first font they encounter in the Helvetica family. One would think this would be Helvetica, but on my system it was defaulting to Helvetica 95 Black. I even tried renaming the font file to see if that was the cause, and no matter the filename, the result was that the page would default to Helvetica Black. I've found this to be the case with Arial as well.
So other than attempting to account for every single flavor of Helvetica, Arial, Verdana, Tahoma, ad infinitum, is there a way to force the browser to stop "guessing" at the family and accept only the exact font in question?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于初学者来说,这里是对字体匹配算法的描述,如CSS 2.1 规范(或 CSS 3,如果您愿意的话) 。但这是一个棘手的问题,算法细节概述之前的免责声明就证明了这一点:
另请注意,您必须将任何包含空格的字体名称用单引号或双引号括起来,按照 第 15.3 节。
For starters, here's a description of the font matching algorithm as outlined in the CSS 2.1 specification (or CSS 3, if you prefer). This is a tricky issue though, as is evidenced by the disclaimer before the algorithm's details are outlined:
Also, note that you must enclose any font name containing whitespace with either single or double quotes, as per section 15.3.