css - 浏览器有时会使用错误的字体来渲染图标,导致文字乱码
问题描述
我遇到了一个间歇性问题,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 上的字体系列设置为'Gotham Light', Arial, sans-serif
.
这个错误很少发生,而且很难重现。
解决方案
推荐阅读
- c# - C# Task.Delay(1).Wait() 死锁,但前提是在另一个任务中
- ios - App Store Connect 中的可本地化信息在发布后重置
- html - 如何将由代码创建的 html 表转换为 json 对象?AngularJS
- python - 如何使用 OpenCV 改进图像对齐
- angular - 角度构造函数中的复杂位置很难测试
- reactjs - BrowserRouter的componentWillUnmount问题
- laravel - 我如何在数据函数中获取路由参数以及延迟加载组件
- html - 调整右侧屏幕大小时如何删除多余的空间?
- class - 使用类作为电话簿字典
- python - 无法以编程方式登录网站