【问题标题】:Font support on IE 11IE 11 上的字体支持
【发布时间】:2019-02-15 12:01:05
【问题描述】:

我在 IE 11 上遇到了字体问题。我的某些元素无法接受 font-family。我有.woff.woff2 但它不接受我的字体。我该如何解决这个问题? 这是我的 CSS 代码:

@font-face {
  font-family: 'Roboto';
  font-style: normal;
  font-weight: 100;

  src: url('../../webfonts/roboto/roboto-v18-cyrillic-ext_latin-100.eot'); /* IE9 Compat Modes */
  src: local('Roboto Thin'), local('Roboto-Thin'),
  url('../../webfonts/roboto/roboto-v18-cyrillic-ext_latin-100.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
  url('../../webfonts/roboto/roboto-v18-cyrillic-ext_latin-100.woff2') format('woff2'), /* Super Modern Browsers */
  url('../../webfonts/roboto/roboto-v18-cyrillic-ext_latin-100.woff') format('woff'), /* Modern Browsers */
  url('../../webfonts/roboto/roboto-v18-cyrillic-ext_latin-100.ttf') format('truetype'), /* Safari, Android, iOS */
  url('../../webfonts/roboto/roboto-v18-cyrillic-ext_latin-100.svg#Roboto') format('svg'); /* Legacy iOS */
}

我正在使用font-family 规则,如下所示:

body {
  font-family: Roboto;
}

这是一个结果:

【问题讨论】:

标签: html css fonts


【解决方案1】:

您的问题是您假设Roboto 是一种内置的网络字体,但事实并非如此。你需要引号:

body {
    font-family: 'Roboto';
}

【讨论】:

  • 查看开发者工具并找出哪些样式应用于文本,然后从那里查看。或者您能否发布您的整个 HTML + CSS 代码?
  • 我给定的样式应用了所有文本,但有些元素不能接受它
  • 您使用的是什么版本的 HTML?
  • HTML5 这里是我取消选中样式tinyimg.io/i/JkoS0Xp.PNG时的屏幕@
  • 我同意,它似乎在 Safari 中工作。也许添加一个 IE 声明(如 -webkit- 但对于 IE)
【解决方案2】:

您是否检查过 DevTools (F12) 中的网络选项卡?加载时不应出现任何 404。

如果你支持 IE10+(MS 本身不支持 IE9-),你只需要 WOFF2 和 WOFF 格式。 SVG 例如适用于 iOS3-4 或类似的东西......

您应该首先使用不常见的字体系列名称和超常规参数(无斜体、无细或粗体)进行测试:

@font-face {
  font-family: 'test';
  font-style: normal;
  font-weight: 400;

  src: url('../../webfonts/roboto/roboto-v18-cyrillic-ext_latin-100.woff2') format('woff2'), /* Super Modern Browsers */
  url('../../webfonts/roboto/roboto-v18-cyrillic-ext_latin-100.woff') format('woff') /* Modern Browsers */
;
}

body,
body * {
  font-family: 'test' !important;
}

它允许您测试相对于您的 CSS 的正确路径(如果您使用 Sass 和 _partials 或 LESS 或 PostCSS 或 Stylus,则为编译的 CSS!)。
然后您可以将font-weight: 100; 添加到您的@-声明和规则中(并删除像body * 和!important :p 这样的测试位)。
然后更改字体系列的名称。

【讨论】:

  • 我解决了我的问题。这是font-weight: problem顺便说一句谢谢:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-22
  • 1970-01-01
  • 2014-07-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多