【问题标题】:Custom icon set not displaying in Safari自定义图标集未在 Safari 中显示
【发布时间】:2020-06-20 19:38:30
【问题描述】:

我使用 FontForge 创建了一些图标,这些图标适用于除 Safari 之外的所有现代浏览器。是什么导致 Safari 成为唯一不显示字体的浏览器?

这是正在使用的 SCSS:

@font-face {
    font-family: 'MyFont';
    src: url('/assets/fonts/MyFont.woff2') format('woff2');
    font-weight: normal;
    font-style: normal;
}

.my-font-icon {
    font-family: 'MyFont';
    display: inline-block;
    speak: none;
    font-style: normal;
    font-weight: normal;
    font-variant: normal;
    text-transform: none;
    text-rendering: auto;
    line-height: 1;
    -webkit-font-smoothing: antialiased;

    &:before {
        font-family: 'MyFont';
        display: inline-block;
        speak: none;
        font-style: normal;
        font-weight: normal;
        font-variant: normal;
        text-transform: none;
        text-rendering: auto;
        line-height: 1;
        -webkit-font-smoothing: antialiased;
    }

    &.my-font-questions:before {
        content: "\0001";
    }
    &.my-font-chevron-left:before {
        content: "\0002";
    }
    &.my-font-close:before {
        content: "\0003";
    }
}

【问题讨论】:

  • 是 Safari 中加载的字体,例如字体是否在网络选项卡中列为 http 200 响应?
  • @anderssonola 是的,它正在加载200

标签: css sass fonts safari


【解决方案1】:

Safari 需要 TrueType/ttf 字体版本,实际上您应该包括几种不同的类型,而不仅仅是最现代的 woff2 类型。这是 CSS 技巧文章 here 中的示例列表,浏览器会找到它理解的字体并呈现该字体:

@font-face {
  font-family: 'MyWebFont';
  src: url('webfont.eot'); /* IE9 Compat Modes */
  src: url('webfont.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
       url('webfont.woff2') format('woff2'), /* Super Modern Browsers */
       url('webfont.woff') format('woff'), /* Pretty Modern Browsers */
       url('webfont.ttf')  format('truetype'), /* Safari, Android, iOS */
       url('webfont.svg#svgFontName') format('svg'); /* Legacy iOS */
}

FontForge 应该为您提供这些其他字体类型,但如果没有,您需要前往 FontSquirrel 进行渲染(如果您有这样做的许可和权限):

https://www.fontsquirrel.com/tools/webfont-generator

【讨论】:

  • 从 v12 开始,Safari 完全支持 woff2 ?
  • 它应该被支持,我们在 v13 中遇到了问题。
  • 我们已尝试使用您的上述解决方案,但没有成功。图标仍然不显示。它显示为一个空白区域。
  • @GetOffMyLawn 你的字体文件放对了吗?
  • 看起来 FontForge 有一个检查器,你的字体是否通过了正确的检查? designwithfontforge.com/en-US/…@GetOffMyLawn
猜你喜欢
  • 2020-01-20
  • 1970-01-01
  • 1970-01-01
  • 2018-12-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-12-10
相关资源
最近更新 更多