代码之家  ›  专栏  ›  技术社区  ›  Get Off My Lawn

自定义图标集未在Safari中显示

  •  0
  • Get Off My Lawn  · 技术社区  · 5 年前

    @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";
        }
    }
    
    1 回复  |  直到 5 年前
        1
  •  0
  •   Nathaniel Flick    5 年前

    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 */
    }
    

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