0

我在这里需要一些帮助。我们为我们的站点使用自定义字体(非标准字体)并使用以下字体声明(在我们的全局 css 中声明):

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

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

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

所以,到目前为止,它的表现超出了我们的预期……除了 IE7 的一个问题。

出于某种原因,IE7 会下载所有 EOT 文件(如在字体声明中声明/使用的那样),即使当前在浏览器中加载的页面仅使用了一种或两种字体变体。

请告知,我们缺少什么/需要更改什么来解决此问题?

4

1 回答 1

2

You can use Conditional Comments for it via sniffing the browsers version.

HTML:

<html>
    <head>
        <title>Example</title>

        <!--[if lte IE 8]> <link rel="stylesheet" href="font-face-lte8.css" type="text/css" media="" title="" charset="utf-8"> <![endif]-->
        <!--[if gte IE 9]> <link rel="stylesheet" href="font-face-gte9.css" type="text/css" media="" title="" charset="utf-8"> <![endif]-->
        <link rel="stylesheet" href="font-face-allothers.css" type="text/css" media="" title="" charset="utf-8">

    </head>
</html>

CSS for font-face-lte8.css:

@font-face {
    font-family: 'MyWebFont';
    src: url('webfont.eot?#iefix') format('embedded-opentype'); /* IE6-IE8 */
    font-weight: normal;
    font-style: normal;
}

@font-face {
    font-family: 'MyWebFont';
    src: url('webfontbold.eot?#iefix') format('embedded-opentype'); /* IE6-IE8 */
    font-weight: bold;
    font-style: normal;
}

@font-face {
    font-family: 'MyWebFont';
    src: url('webfontitalic.eot?#iefix') format('embedded-opentype'); /* IE6-IE8 */
    font-weight: normal;
    font-style: italic;
}

CSS for font-face-gte9.css

@font-face {
    font-family: 'MyWebFont';
    src: url('webfont.eot'); /* IE9 Compat Modes */
    font-weight: normal;
    font-style: normal;
}

@font-face {
    font-family: 'MyWebFont';
    src: url('webfontbold.eot'); /* IE9 Compat Modes */
    font-weight: bold;
    font-style: normal;
}

@font-face {
    font-family: 'MyWebFont';
    src: url('webfontitalic.eot'); /* IE9 Compat Modes */
    font-weight: normal;
    font-style: italic;
}

CSS for font-face-allothers.css

@font-face {
    font-family: 'MyWebFont';
    src: url('webfont.woff') format('woff'), /* Modern Browsers */
         url('webfont.ttf')  format('truetype'), /* Safari, Android, iOS */
         url('webfont.svg#svgFontName') format('svg'); /* Legacy iOS */
    font-weight: normal;
    font-style: normal;
}

@font-face {
    font-family: 'MyWebFont';
    src: url('webfontbold.woff') format('woff'), /* Modern Browsers */
         url('webfontbold.ttf')  format('truetype'), /* Safari, Android, iOS */
         url('webfontbold.svg#svgFontName') format('svg'); /* Legacy iOS */
    font-weight: bold;
    font-style: normal;
}

@font-face {
    font-family: 'MyWebFont';
    src: url('webfontitalic.woff') format('woff'), /* Modern Browsers */
         url('webfontitalic.ttf')  format('truetype'), /* Safari, Android, iOS */
         url('webfontitalic.svg#svgFontName') format('svg'); /* Legacy iOS */
    font-weight: normal;
    font-style: italic;
}

This will solve the problem.
For info: IE9 supports TTF and WOFF files, so IE9 may download these too, even if he didn't need them.

于 2012-06-04T15:50:46.063 回答