【发布时间】:2019-11-10 00:13:51
【问题描述】:
Chrome 出现间歇性问题,无法呈现正确的字体来显示图标。
我正在使用 icomoon.io 创建一组自定义图标作为字体,并使用以下 css(由 icomoon 自动生成)来显示这些自定义图标。
@font-face {
font-family: 'eIconFont';
src: url('fonts/eIconFontV3.eot?kmqo7q');
src: url('fonts/eIconFontV3.eot?kmqo7q#iefix') format('embedded-opentype'), url('fonts/eIconFontV3.woff2?kmqo7q') format('woff2'), url('fonts/eIconFontV3.ttf?kmqo7q') format('truetype'), url('fonts/eIconFontV3.woff?kmqo7q') format('woff'), url('fonts/eIconFontV3.svg?kmqo7q#eIconFontV3') format('svg');
font-weight: normal;
font-style: normal;
}
[class^="eIcon-"], [class*=" eIcon-"] {
/* use !important to prevent issues with browser extensions that change fonts */
font-family: 'eIconFont' !important;
speak: none;
font-style: normal;
font-weight: normal;
font-variant: normal;
text-transform: none;
line-height: 1;
/* Enable Ligatures ================ */
letter-spacing: 0;
-webkit-font-feature-settings: "liga";
-moz-font-feature-settings: "liga=1";
-moz-font-feature-settings: "liga";
-ms-font-feature-settings: "liga" 1;
font-feature-settings: "liga";
-webkit-font-variant-ligatures: discretionary-ligatures;
font-variant-ligatures: discretionary-ligatures;
/* Better Font Rendering =========== */
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.eIcon-support:before {
content: "\e93b";
}
.eIcon-collapse:before {
content: "\e935";
}
.eIcon-expand:before {
content: "\e936";
}
html 看起来像这样:
<span class="eIcon-support" title="Support">
::before
</span>
结果如下所示:
查看 Chrome 开发工具,我可以看到字体文件本身可以从我们的 CDN 正常加载,但我注意到在 Elements > Computed > Rendered Fonts 下显示 Times New Roman,当该值通常为eIconFontV3。奇怪的是,浏览器尝试使用 Times New Roman,而 body 上设置的 font-family 是'Gotham Light', Arial, sans-serif。
这个错误很少发生,而且很难重现。
【问题讨论】:
-
@font-face是否应该有两个src值?似乎一个会覆盖另一个。 -
@showdev 我不确定为什么会有两个
src,这正是 icomoon.io 生成的。可能会更加谨慎的后备? -
可能是这样。我找到了this,但我不确定它是否相关。你有没有看到类似的错误?
-
@showdev 不,很遗憾控制台中没有显示错误。