代码之家  ›  专栏  ›  技术社区  ›  AngryHacker

什么是现代@FONT face声明?

  •  0
  • AngryHacker  · 技术社区  · 6 年前

    多年来,我使用了以下字体声明:

    @font-face {
      font-family: 'museo_sans_rounded';
      font-style: normal;
      font-weight: 500;
      src:  url('../fonts/museo/museosansrounded-300-webfont.eot');
      src:  url('../fonts/museo/museosansrounded-300-webfont.eot?#iefix') format('embedded-opentype'), 
            url('../fonts/museo/museosansrounded-300-webfont.woff2') format('woff2'), 
            url('../fonts/museo/museosansrounded-300-webfont.woff') format('woff'), 
            url('../fonts/museo/museosansrounded-300-webfont.ttf') format('truetype'), 
            url('../fonts/museo/museosansrounded-300-webfont.svg#museo_sans_rounded300') format('svg');
    }      
    

    现在我只需要支持IE11和所有的现代浏览器。这个声明可以简化吗?

    2 回复  |  直到 6 年前
        1
  •  2
  •   Yvonne Aburrow    6 年前

    根据本文 embedding custom fonts 使用 @font-face :

    @FONT face规则允许在网页上加载自定义字体。一旦添加到样式表中,规则将指示浏览器从承载该字体的位置下载该字体,然后按照CSS中的指定显示该字体。

    有不同级别的浏览器支持不同的字体。趋势似乎是,您可以通过提供Woff和Woff2摆脱困境,但这是他们对“最深入的浏览器支持”的建议:

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

    对于IE11:

    @font-face {
      font-family: 'MyWebFont';
      src: url('myfont.woff2') format('woff2'),
           url('myfont.woff') format('woff'),
           url('myfont.ttf') format('truetype');
    }
    
        2
  •  0
  •   Cuong Hoang    6 年前
    .eot ==> for IE9 Compat Modes
    .eot?#iefix ==> for IE6-IE8 
    .woff2 ==> for super Modern browser like Chrome, Firefox...
    .woff ==> for pretty Modern.. so to speak
    .ttf ==> specially for Safari, Android, iOS
    .svg#svgFontName ==> just for Legacy iOS