我遇到了间歇性的问题,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
。奇怪的是,当主体上设置的字体系列为'Gotham Light', Arial, sans-serif
时,浏览器尝试使用Times New Roman。
此错误很少发生,并且很难重现。