0

我在网站上使用@font-face。该代码有效,并且在 Firefox、Chrome 和 Opera 中,@font-face 字体可以完美加载。使用的代码与 Font Squirrel 生成的代码相同。这是@font-face 代码:

@font-face {
    font-family: 'OpenSansRegular';
    src: url('fonts/OpenSans-Regular-webfont.eot');
    src: url('fonts/OpenSans-Regular-webfont.eot?#iefix') format('embedded-opentype'),
         url('fonts/OpenSans-Regular-webfont.woff') format('woff'),
         url('fonts/OpenSans-Regular-webfont.ttf') format('truetype'),
         url('fonts/OpenSans-Regular-webfont.svg#OpenSansRegular') format('svg');
    font-weight: normal;
    font-style: normal;

}

然后使用以下代码调用字体:

font-family: "OpenSansRegular",Arial,sans-serif;

但是,在 IE9 中它仍然可以工作,但是非常笨重。最初加载页面时,首先加载Arial字体,大约 1 或 2 秒OpenSansRegular后加载字体。这显然会破坏网站的体验,因为页面加载了一种字体,然后在一段时间后将另一种字体引导到页面上。

有没有办法在仍然使用@font-face 的同时防止这种情况发生?

4

1 回答 1

1

在 IE 9 中,完全支持使用 data: 属性。在这种情况下,您可以通过以下方式修改 CSS:

@font-face {
    font-family: 'OpenSansRegular';
    src: url('data:font/eot;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAggg=='); /* IE 9 */
    font-weight: normal;
    font-style: normal;
}

这将确保仅当 CSS 完全加载时,它也会加载字体。希望能帮助到你。

于 2012-06-06T09:00:12.877 回答