[英]Why is Safari’s default font tracking/letter-spacing different than other browsers?
I'm experiencing an issue with Safari where a block of text using webfonts (not sure webfonts are the issue) is wrapping differently in Safari than it is in any other browser.我遇到了 Safari 的问题,其中使用 webfonts 的文本块(不确定 webfonts 是问题)在 Safari 中的换行方式与在任何其他浏览器中的不同。 In this particular instance, we're designing these blocks to look like they're set to
text-align: justify;
在这个特定的例子中,我们将这些块设计为看起来像它们被设置为
text-align: justify;
but they're actually set to text-align: left;
但它们实际上设置为
text-align: left;
. .
text-align: justify;
is undesired in this setting as it does a poor job of calculating the space between words.在此设置中不受欢迎,因为它在计算单词之间的空间方面做得很差。
Important things to know:需要了解的重要事项:
A visual aid:视觉辅助:
Details about the layout and dimensions:有关布局和尺寸的详细信息:
1220px
.1220px
。padding: 0 calc(129 / 1220 * 100vw);
padding: 0 calc(129 / 1220 * 100vw);
which computes to 129px
.129px
。962px
.962px
的可用内容空间。letter-spacing
is set to 0 by default for all content.letter-spacing
默认设置为 0。 So, anyone have any idea why Safari seems to have exaggerated tracking/letter-spacing?那么,有人知道为什么 Safari 似乎夸大了跟踪/字母间距吗?
EDIT编辑
We just launched the site in question, so you can see the issue in action here: https://www.typography.com/fonts/hoefler-text/overview我们刚刚启动了相关网站,因此您可以在此处查看实际问题: https : //www.typography.com/fonts/hoefler-text/overview
Well, there's a bunch of stuff at play.嗯,有很多东西在玩。
First of all Chrome and Safari use different defaults for rendering text, But in addition to that Chrome on different versions of MacOS or Windows will render text differently too because of how the system font rendering works.首先,Chrome 和 Safari 使用不同的默认渲染文本,但除此之外,由于系统字体渲染的工作方式,不同版本的 MacOS 或 Windows 上的 Chrome 也会以不同的方式渲染文本。
You can typically make Safari and Chrome (on the same system) feel a bit closer by setting your text CSS to:通过将文本 CSS 设置为:
text-rendering: optimizeLegibility
Since this is the default on Chrome but Safari defaults to optimizeSpeed
text-rendering: optimizeLegibility
因为这是 Chrome 上的默认设置,但 Safari 默认设置为optimizeSpeed
It might also be wise to explicitly set: font-feature-settings: "kern";
显式设置也可能是明智的:
font-feature-settings: "kern";
and font-smoothing: antialiased
(note those both need vendor prefixes)和
font-smoothing: antialiased
(注意那些都需要供应商前缀)
Next, make sure to specify a numeric font weight.接下来,确保指定数字字体粗细。 Eg:
font-weight: 400
for "regular".例如:
font-weight: 400
表示“常规”。 (The browsers might not pick the same weight for the normal/bold keywords) (浏览器可能不会为正常/粗体关键字选择相同的权重)
Finally, make sure you're serving up the most optimized version of a webfont (Typekit & Google usually do this for you, but it's an issue if you're self-hosting the fonts)最后,确保您提供最优化的网络字体版本(Typekit 和 Google 通常会为您执行此操作,但如果您自行托管字体,则这是一个问题)
Edit:编辑:
It might be worth forcing both Chrome and Safari to create a "compositing layer" (basically means its GPU accelerated).强制 Chrome 和 Safari 创建一个“合成层”(基本上意味着它的 GPU 加速)可能是值得的。 You can do that with
backface-visibility: hidden
.你可以用
backface-visibility: hidden
做到这一点。 Though I suspect this is a MacOS specific thing and there may not be a solution in the browser.虽然我怀疑这是一个 MacOS 特定的东西,浏览器中可能没有解决方案。
Adding font-feature-settings: "kern";
添加
font-feature-settings: "kern";
to the element for the fonts solved my problem with Safari not rendering the letter-spacing properly.到字体元素解决了我的问题,Safari 无法正确呈现字母间距。
I had the similar issue while building an html banner using a .woff font: Safari was applying an exaggerated tracking/letter-spacing.我在使用 .woff 字体构建 html 横幅时遇到了类似的问题:Safari 正在应用夸大的跟踪/字母间距。 Bryce's suggestion to use
font-weight: 400;
Bryce 建议使用
font-weight: 400;
fixed the issue .解决了这个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.