简体   繁体   English

为什么 Safari 的默认字体跟踪/字母间距与其他浏览器不同?

[英]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:需要了解的重要事项:

  • As I mentioned, the layout uses webfonts.正如我提到的,布局使用 webfonts。 It doesn't matter which webfonts (I've reviewed hundreds and it happens for all).哪种 webfonts 无关紧要(我已经审查了数百种并且适用于所有人)。
  • The entire page, including padding and font-size, uses viewport width (vw).整个页面,包括内边距和字体大小,都使用视口宽度 (vw)。 The idea here is that the block of text scales equally for all browser sizes and retains it's layout, including rags.这里的想法是文本块对于所有浏览器大小均等缩放并保留其布局,包括破布。

A visual aid:视觉辅助:

在此处输入图片说明


Details about the layout and dimensions:有关布局和尺寸的详细信息:

  • Frame 1: Safari desktop.框架 1:Safari 桌面。
  • Frame 2: Chrome desktop.第 2 帧:Chrome 桌面。
  • Frame 3: Chrome at 50% opacity over Safari.第 3 帧:Chrome 的不透明度比 Safari 高 50%。
  • Window width in this screenshot is 1220px .此屏幕截图中的窗口宽度为1220px
  • Left/right padding is padding: 0 calc(129 / 1220 * 100vw);左/右填充是padding: 0 calc(129 / 1220 * 100vw); which computes to 129px .计算为129px
  • That leaves the available content space of 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM