html - iOS 9 上 Internet Explorer 11 和 Safari 的强元素上的不同字体
问题描述
我有一个带有两种字体的网络应用程序,Amatic SCh1
和h2
Open Sans 其余的。该网页strong
在大多数浏览器上都可以正常显示文本:
对于 iOS 9 上的 Safari(在 iPhone 4S 上测试)和 Windows 8.1 上的 Internet Explorer 11(在 LambdaTest 上测试),strong
元素使用h1
和h2
元素中的字体:
这些元素的相关 CSS 是:
@font-face {
font-family: 'Amatic SC';
font-style: normal;
font-weight: 400;
src: url(/fonts/amatic-sc-v13-latin-regular.woff2) format('woff2'), url(/fonts/amatic-sc-v13-latin-regular.woff) format('woff'); }
@font-face {
font-family: 'Amatic SC';
font-style: bold;
font-weight: 700;
src: url(/fonts/amatic-sc-v13-latin-700.woff2) format('woff2'), url(/fonts/amatic-sc-v13-latin-700.woff) format('woff'); }
@font-face {
font-family: 'Open Sans';
font-style: normal;
font-weight: 400;
src: url(/fonts/open-sans-v17-latin-regular.woff2) format('woff2'), url(/fonts/open-sans-v17-latin-regular.woff) format('woff');
}
@font-face {
font-family: 'Open Sans';
font-style: bold;
font-weight: 700;
src: url(/fonts/open-sans-v17-latin-700.woff2) format('woff2'), url(/fonts/amatic-sc-v13-latin-regular.woff) format('woff');
}
body {
font-family: 'Open Sans', sans-serif;
}
h1, h2 {
margin: 0.5rem 0 0.5rem 0;
text-align: left;
font-family: Amatic SC, cursive;
font-weight: bold;
}
如果您想进一步检查,该网站位于www.emotionathletes.org 。
在 iOS Safari 和 Internet Explorer 上使用不同字体的原因是什么?
最小的可重现示例
在评论之后,我将问题缩小到字体的加载。如果我将它们加载到head
链接到 Google 字体的 HTML 中,则页面显示良好。@font-face
如果我使用from a woff
or文件在 CSS 中本地加载它们woff2
,则强元素在 iPhone 4S 上的 iOS 9 和 Windows 8.1 上的 Internet Explorer 11 上以不同的字体显示。在 CSS 中加载字体的顺序不会改变结果。
一个最小的可重现示例有 HTML 文件strong.html
:
<!DOCTYPE html>
<html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"><meta charset="utf-8"><meta name="viewport" content="width=device-width, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
<link rel="stylesheet" type="text/css" href="strong.css">
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Open+Sans&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Amatic+SC&display=swap" rel="stylesheet">
</head>
<body>
<h2>Summary</h2>
<p>The Bulgy series, whose first season is "Emotion Athletes", has the following purposes:</p>
<ul>
<li>
transform the <strong>difficulties</strong> of the <strong>pandemic</strong> into <strong>opportunities</strong> for children to <strong>recognise what they are feeling, understand the reason, and use their emotions</strong>;
</li>
</ul>
</body>
</html>
和 CSS 文件strong.css
:
/*
Amatic SC and Open Sans are Google Fonts:
https://fonts.google.com/specimen/Amatic+SC?sidebar.open=true&selection.family=Open+Sans#about
https://fonts.google.com/specimen/Open+Sans?sidebar.open=true&selection.family=Open+Sans#about
*/
/* comment these @font-faces for the page to work properly. */
@font-face {
font-family: 'Amatic SC';
font-style: normal;
font-weight: 400;
src: url(/fonts/amatic-sc-v13-latin-regular.woff2) format('woff2'), url(/fonts/amatic-sc-v13-latin-regular.woff) format('woff'); }
@font-face {
font-family: 'Amatic SC';
font-style: bold;
font-weight: 700;
src: url(/fonts/amatic-sc-v13-latin-700.woff2) format('woff2'), url(/fonts/amatic-sc-v13-latin-700.woff) format('woff'); }
@font-face {
font-family: 'Open Sans';
font-style: normal;
font-weight: 400;
src: url(/fonts/open-sans-v17-latin-regular.woff2) format('woff2'), url(/fonts/open-sans-v17-latin-regular.woff) format('woff');
}
@font-face {
font-family: 'Open Sans';
font-style: bold;
font-weight: 700;
src: url(/fonts/open-sans-v17-latin-700.woff2) format('woff2'), url(/fonts/amatic-sc-v13-latin-regular.woff) format('woff');
}
body {
font-family: 'Open Sans', sans-serif;
}
h1, h2 {
font-family: 'Amatic SC', cursive;
}
我在www.emotionathletes.org/strong.html上放了一个现场版本,在www.emotionathletes.org/strong.css上带有 CSS 文件。
出于我自己的原因,我更喜欢从我的服务器提供字体文件,而不是从 Google 字体查询它们。如何在本地提供字体文件并仍然在 Safari 和 Internet Explorer 上正确显示它们?
解决方案
问题出在代码中,我今天在更改主字体时发现了该代码:
对于Open Sans
at 700
,woff
文件路径是:
/fonts/amatic-sc-v13-latin-regular.woff
并且应该是:
/fonts/open-sans-v17-latin-700.woff
较旧的浏览器使用woff
and not woff2
,因此他们完全按照他们的指示行事。我现在解决了这个问题。
故事的寓意:如果使用本地字体来提高性能,请确保将 CSS 正确连接到文件路径。
推荐阅读
- amp-html - 如何通过 amp-validation 为 div 设置动画?
- javascript - 对象的值在 React 中总是显示“未定义”
- html - 在边缘放置白色填充和颜色
- python - Django:用“models.TimeField”计算
- c++ - 重载一元运算符,特别是使用friend关键字进行后增量和预增量
- typescript - 如何修复“找不到名称'ClipboardItem'”错误?
- python - 在 Python 中使用 Flask 时线程运行两次?
- java - 编写一个 java 程序,其中包含一个名为 getVowel() 的函数,该函数采用链表
- python - 以指定频率为时间序列数据前向填充某些列
- chocolatey - 我的包不支持 Windows Server(Chocolatey 测试环境):我如何“跳过”安装,所以自动测试不会失败?