是否可以强制“字体优先”?在样式表中?

发布于 2024-09-25 11:02:39 字数 647 浏览 0 评论 0原文

在各种浏览器中,当使用特定字体(例如 - 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

陌生 2024-10-02 11:02:39

对于初学者来说,这里是对字体匹配算法的描述,如CSS 2.1 规范(或 CSS 3,如果您愿意的话) 。但这是一个棘手的问题,算法细节概述之前的免责声明就证明了这一点:

由于没有公认的通用字体属性分类法,因此必须仔细匹配属性与字体。这些属性按照明确定义的顺序进行匹配,以确保该匹配过程的结果在各个 UA 之间尽可能一致(假设向每个 UA 提供相同的字体库)。

另请注意,您必须将任何包含空格的字体名称用单引号或双引号括起来,按照 第 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:

Because there is no accepted, universal taxonomy of font properties, matching of properties to font faces must be done carefully. The properties are matched in a well-defined order to insure that the results of this matching process are as consistent as possible across UAs (assuming that the same library of font faces is presented to each of them).

Also, note that you must enclose any font name containing whitespace with either single or double quotes, as per section 15.3.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文