【问题标题】:Custom font sometimes renders in italics in IE8 / IE7自定义字体有时在 IE8 / IE7 中以斜体呈现
【发布时间】:2014-06-04 16:51:25
【问题描述】:

在 IE7 和 IE8 中,当使用自定义 Web 字体时,文本有时会以斜体呈现,即使我明确设置了 font-style: normal。问题是零星的——它会渲染几次,然后我刷新,一切都用斜体显示,然后我刷新,它又恢复正常了。

我正在使用这个@font-face 声明:

@font-face {
    font-family: 'DIN';
    src: url('fonts/DINWeb.eot');
    src: url('fonts/DINWeb.eot?#iefix') format('embedded-opentype'),
         url('fonts/DINWeb.woff') format('woff');
    font-weight: normal;
    font-style: normal;
}
@font-face {
    font-family: 'DIN';
    src: url('fonts/DINWeb-Bold.eot');
    src: url('fonts/DINWeb-Bold.eot?#iefix') format('embedded-opentype'),
         url('fonts/DINWeb-Bold.woff') format('woff');
    font-weight: bold;
    font-style: normal;
}
@font-face {
    font-family: 'DIN';
    src: url('fonts/DINWeb-Ita.eot');
    src: url('fonts/DINWeb-Ita.eot?#iefix') format('embedded-opentype'),
         url('fonts/DINWeb-Ita.woff') format('woff');
    font-weight: normal;
    font-style: italic;
}
@font-face {
    font-family: 'DIN';
    src: url('fonts/DINWeb-BoldIta.eot');
    src: url('fonts/DINWeb-BoldIta.eot?#iefix') format('embedded-opentype'),
         url('fonts/DINWeb-BoldIta.woff') format('woff');
    font-weight: bold;
    font-style: italic;
}

this article 上的 a comment 表明它可能与 @font-face 声明的顺序有关:但是唯一阻止问题的方法是完全删除斜体声明。

Another Stack Overflow answer 建议使用 Font Squirrel @font-face 生成器;但是我不能这样做,因为我使用的网络字体文件有 DRM。

有没有办法在不完全删除斜体声明的情况下解决这个问题?

更新:经过进一步调查,似乎这个问题也会影响 IE8,而不仅仅是兼容模式。

【问题讨论】:

  • 您没有提供正在使用的 HTML。尝试使用唯一的@font-face 姓氏。示例:DINnormal, DINbold, DINitalic, DINboldItalic。在SO Answer 中查看 CSS 和 HTML 示例。如果创建唯一名称可以解决您的问题,我会回答。干杯!
  • @arttronics 谢谢,原来独特的字体系列名称最终解决了问题。如果你写了一个答案,我会继续接受它。
  • 亚当夏普,很高兴这对你有用……我已经发布了答案。干杯!

标签: css internet-explorer-8 internet-explorer-7 font-face italic


【解决方案1】:

为您的每个 @font-face font-family 名称创建一个自定义名称。

例子:

@font-face {
    font-family: 'DINnormal';
    src: url('fonts/DINWeb.eot');
    src: url('fonts/DINWeb.eot?#iefix') format('embedded-opentype'),
         url('fonts/DINWeb.woff') format('woff');
    font-weight: normal;
    font-style: normal;
}
@font-face {
    font-family: 'DINbold';
    src: url('fonts/DINWeb-Bold.eot');
    src: url('fonts/DINWeb-Bold.eot?#iefix') format('embedded-opentype'),
         url('fonts/DINWeb-Bold.woff') format('woff');
    font-weight: bold;
    font-style: normal;
}
@font-face {
    font-family: 'DINitalic';
    src: url('fonts/DINWeb-Ita.eot');
    src: url('fonts/DINWeb-Ita.eot?#iefix') format('embedded-opentype'),
         url('fonts/DINWeb-Ita.woff') format('woff');
    font-weight: normal;
    font-style: italic;
}
@font-face {
    font-family: 'DINboldItalic';
    src: url('fonts/DINWeb-BoldIta.eot');
    src: url('fonts/DINWeb-BoldIta.eot?#iefix') format('embedded-opentype'),
         url('fonts/DINWeb-BoldIta.woff') format('woff');
    font-weight: bold;
    font-style: italic;
}

定义完这些 CSS 规则后,就可以包含特定的 CSS 规则了:

li {
  font: 18px/27px 'DINnormal', Arial, sans-serif;
}

【讨论】:

    【解决方案2】:

    如果您像我一样在使用 TypeKit 字体时遇到类似问题时遇到此问题,this entry from the TypeKit blog 将解释如何为 TypeKit 字体的每种粗细和样式强制使用唯一的 font-family 名称来解决该问题。

    【讨论】:

    • 我可以支持这个。我看到了这条评论,它帮助我解决了我在使用 Typekit 时遇到的问题。谢谢大佬。
    【解决方案3】:

    我遇到了类似的问题,在使用 IE8(模拟器)时,网络字体以斜体显示,经过挖掘和挖掘,我发现一篇文章表明模拟器有时会产生误导,尤其是在涉及 webFonts 时,以及它的建议在实际的 IE8 中尝试该站点,因为我使用的是 Windows 7 机器,所以我无法下载真实的东西,所以我使用了这个名为 http://www.browserstack.com/ 的站点(没有测试人员或假浏览器。在包括 Internet Explorer 在内的真实浏览器中进行测试6、7、8、9、10 和 11。)

    我注意到我的字体不再是斜体了:D

    这是我阅读的文章的链接,

    http://blog.typekit.com/2013/03/14/the-dangers-of-cross-browser-testing-with-ie9s-browser-modes/

    希望这对你们有帮助,如果我在研究时遇到这样的事情真的会为我节省几个小时

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-03-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-07
      • 2022-08-08
      相关资源
      最近更新 更多