使用 @font-face 在 IE 中显示无样式内容的 Flash

发布于 2024-12-29 18:29:45 字数 705 浏览 4 评论 0原文

我正在开发一个网站,该网站使用 Open Sans 字体作为正文,并使用 Font Squirrel 生成的 EOT、SVG、WOFF 和 TTF 字体文件和样式表。我首先将字体 CSS 包含在页面标题中。但是,当我在 IE7、IE8 甚至 IE9 中查看该网站时,在 Open Sans 启动之前,我会看到 Times Roman 中的所有内容。这在其他浏览器中不会发生。

谁能建议我可以阻止这种情况发生吗?这是我用于该字体的 Font Squirrel CSS:

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

I'm working on a site which uses the Open Sans typeface for the body text, with EOT, SVG, WOFF and TTF font files and stylesheet generated by Font Squirrel. I've included my fonts CSS first in my page header. But when I view the site in IE7, IE8 and even IE9 I get a flash of everything in Times Roman before the Open Sans kicks in. This isn't happening in the other browsers.

Can anyone suggest a way I could stop this happening? Here's the Font Squirrel CSS I'm using for that font:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

记忆消瘦 2025-01-05 18:29:45

下载自定义字体时您看到的内容并未在上面的代码中定义。它是在整个 CSS 代码中的其他 font-family 指令中定义的。

在“OpenSansRegular”值后添加其他字体,以逗号分隔。从右到左:

  • 右侧是您的字体系列。 serifsans-serifmonospacecursive耶 Comic Sans!) 。在这里,OpenSansSth 是...sans-serif
    你的浏览器有这些家族的默认字体,Arial、Verdana 或 Linux 中的其他字体,等等。当你不为他选择时,这是用户的选择。默认系列是 serif,Windows 中的默认字体是“Times New Roman”。这就是为什么您将 Times New Roman 视为 IE 中的 FOUC。
  • 然后是与您的自定义字体尽可能接近的网络安全字体。这里它是无衬线字体,如 Verdana 或 Arial。也许 sans-serif 和 Verdana 是一样的,但你永远不确定(尤其是 Linux 用户),所以
  • 在你的自定义字体和网络安全字体之间添加两者,你可以添加可以在很多操作系统中安装的字体但不像那些随 MS Office、Adobe Reader、OS X、Adobe Creative Suite 等安装的那样是网络安全的。您会在 10% 到 90% 的访问者计算机中找到它们,但不是 100%。不是每个人都安装 Creative Suite(只有网络专业人士和其他设计师)和 MS Office(我使用 LibreOffice),并且 XP、Vista 和 7 中安装了不同的字体
  • ,最左边的值将是您为自定义字体指定的自定义名称。站点中的 OpenSansRegular

例如:

         nav { font-family: 'Custom_at-font-face','closest font to the font-face one but certainly rarely found on computers by default', 'less close, 'not close but same family', Verdana,sans-serif;
         }

带有百分比的兼容性表(可能有点旧)http://www.codestyle.org/css/font-family/
不要使用 10 个值,3 到 6 个值就足够了;)在 2012 年,@font-face 可能会导致渲染问题,具体取决于浏览器和操作系统(别名),但它得到了很好的支持,因此您可以缩短字体系列。

What you see while the custom font is being downloaded isn't defined in the above code. It's defined in your other font-family instructions throughout your CSS code.

Add other fonts after 'OpenSansRegular' value, separated by commas. From right to left:

  • on the right, the family of your font. serif, sans-serif, monospace or cursive (yay Comic Sans!). Here, OpenSansSth is ... sans-serif.
    Your browser has a default for these families, Arial, Verdana or some other font in Linux, whatever. It's the user choice when you don't choose for him. The default family is serif and the default font in Windows is 'Times New Roman'. That's why you see Times New Roman as a FOUC in IE.
  • then a websafe font that is as close as possible as your custom font. Here it'd be a sans-serif font like Verdana or Arial. Maybe sans-serif and Verdana will be the same thing but you're never sure (especially with Linux users), so add both
  • In between your custom font and the websafe one, you can add fonts that could be installed in quite a few OSes but aren't websafe like the ones installed with MS Office, Adobe Reader, OS X, Adobe Creative Suite, etc You'll find them in 10 to 90% of your visitor computers, but not 100%. Not everybody install a Creative Suite (only web professionals and other designers) and MS Office (I use LibreOffice) and there are different fonts installed in XP, Vista and 7
  • finally, the leftmost value will be the custom name you gave to your custom font. OpenSansRegular in your site

Ex:

         nav { font-family: 'Custom_at-font-face','closest font to the font-face one but certainly rarely found on computers by default', 'less close, 'not close but same family', Verdana,sans-serif;
         }

Compatibility tables with percentages (maybe a bit old) http://www.codestyle.org/css/font-family/
Don't use 10 values, 3 to maybe 6 will be enough ;) In 2012 @font-face may cause rendering problems depending on the browser and the OS (aliasing) but it's very well supported so you can shorten your font-families.

深海里的那抹蓝 2025-01-05 18:29:45

用于隐藏 @font-face FOUC 的 jQuery 插件可以在这里找到:如何知道字体(@font-face)是否已经加载已加载? 从此线程中删除了代码块,因为我一直在那边更新它。

jQuery plugin to hide FOUC of @font-face can be found here: How to know if a font (@font-face) has already been loaded? Removed the code block from this thread as I have been updating it over there.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文