【问题标题】:Webfont Not Working in Chrome and FirefoxWebfont 在 Chrome 和 Firefox 中不起作用
【发布时间】:2015-06-18 23:02:03
【问题描述】:

所以,我正在尝试将 StateFace 字体导入我正在开发的网络应用程序中。我正在使用以下 CSS:

@font-face {
  font-family: 'StateFace Regular';
  src: url('../fonts/StateFace-Regular-webfont.eot');
  src: url('../fonts/StateFace-Regular-webfont.eot?#iefix') format('embedded-opentype'), url('../fonts/StateFace-Regular-webfont.woff') format('woff'), url('../fonts/StateFace-Regular-webfont.ttf') format('truetype'), url('../fonts/StateFace-Regular-webfont.svg#statefaceregular') format('svg');
}
.state {
  font-family: 'StateFace Regular';
  position: relative;
  top: 1px;
  display: inline-block;
  font-style: normal;
  font-weight: normal;
  line-height: 1;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
.state.state-ak:before {
  content: 'A';
}
.state.state-al:before {
  content: 'B';
}
.state.state-ar:before {
  content: 'C';
}
.state.state-az:before {
  content: 'D';
}
.state.state-ca:before {
  content: 'E';
}
.state.state-co:before {
  content: 'F';
}
.state.state-ct:before {
  content: 'G';
}
.state.state-de:before {
  content: 'H';
}
.state.state-fl:before {
  content: 'I';
}
.state.state-ga:before {
  content: 'J';
}
.state.state-hi:before {
  content: 'K';
}
.state.state-ia:before {
  content: 'L';
}
.state.state-il:before {
  content: 'N';
}
.state.state-ks:before {
  content: 'P';
}
.state.state-ky:before {
  content: 'Q';
}
.state.state-la:before {
  content: 'R';
}
.state.state-ma:before {
  content: 'S';
}
.state.state-me:before {
  content: 'U';
}
.state.state-mi:before {
  content: 'V';
}
.state.state-mn:before {
  content: 'W';
}
.state.state-mo:before {
  content: 'X';
}
.state.state-ms:before {
  content: 'Y';
}
.state.state-mt:before {
  content: 'Z';
}
.state.state-nc:before {
  content: 'a';
}
.state.state-nd:before {
  content: 'b';
}
.state.state-ne:before {
  content: 'c';
}
.state.state-nh:before {
  content: 'd';
}
.state.state-nj:before {
  content: 'e';
}
.state.state-nm:before {
  content: 'f';
}
.state.state-nv:before {
  content: 'g';
}
.state.state-ny:before {
  content: 'h';
}
.state.state-oh:before {
  content: 'i';
}
.state.state-ok:before {
  content: 'j';
}
.state.state-or:before {
  content: 'k';
}
.state.state-pa:before {
  content: 'l';
}
.state.state-ri:before {
  content: 'm';
}
.state.state-sc:before {
  content: 'n';
}
.state.state-sd:before {
  content: 'o';
}
.state.state-tn:before {
  content: 'p';
}
.state.state-tx:before {
  content: 'q';
}
.state.state-ut:before {
  content: 'r';
}
.state.state-va:before {
  content: 's';
}
.state.state-vt:before {
  content: 't';
}
.state.state-wa:before {
  content: 'u';
}
.state.state-wi:before {
  content: 'v';
}
.state.state-wv:before {
  content: 'w';
}
.state.state-wy:before {
  content: 'x';
}

它在 IE (9-11) 中运行良好,但在 Firefox 或 Chrome 中却不行。我看过了,两个浏览器都在拉入字体文件,其中包含 200(或 304)个内容长度 > 0 的响应,但内容没有以字体显示。但是,Bootstrap 附带的 Glyphicons 字体可以正常工作,而 StateFace 字体可以在其他页面上使用,因此它必须是特定于我的实现的。有什么突出的地方吗?

编辑:css文件在~/Content中,字体文件在~/fonts中

【问题讨论】:

  • 你能用你的目录结构和文件位置编辑你的帖子吗?
  • @CarsonCrane 我正在将它与 Bootstrap 一起编译,使用与 Glyphicons webfonts 相同的目录位置,并且 StateFace 文件与 Glyphicons 文件位于同一目录中。结合 200/304 响应似乎表明它指向正确的位置。

标签: css google-chrome firefox font-face


【解决方案1】:

您的 CSS 中缺少 woff 源调用。您必须添加 woff 源才能获得 chrome 支持。在StackOverFlow 上阅读此答案。我建议使用Font Squirrel Web Font Generator。只需上传您的字体,它就会生成跨浏览器功能所需的所有 CSS。

更新

另一个可能的问题是 Bootstrap less 可能会覆盖您的样式,因为您的 CSS 选择器不够具体。

更新 2

刚刚从font squirrel 下载了字体,它似乎对我来说在firefox 或chrome 中也不起作用。

【讨论】:

  • woff 源在其中。第二个 src 真的很长。
  • 只是一些 CORS 问题。不过,这只是与 ArcGIS 无关的问题。
  • 据 chrome 和 firefox 告诉我,正在应用正确的字体,只是显示不正确。如果我关闭字体,它会更改为页面的默认字体。
  • 在您的控制台中查看您的.state 是否有直通字体系列? @Ixonal
  • 我认为这个问题与@Ixonal 的代码没有任何关系。看起来是源文件的问题。看我的回答。
【解决方案2】:

所以我在 fontsquirrel 上找到了我认为你下载的字体。

Fontsquirrel 自己的演示文件在 Chrome 中不适合我,而且它们的 TTF 格式在 Windows 中也不适用:

我会尝试在其他地方为该文件找到一个镜像并使用它,或者它可能只是直接损坏了,您可能必须找到另一个选项。

【讨论】:

  • 我想知道是不是字体本身。想在打折之前确保我没有做错什么。不过,不知道为什么 IE 正在工作,因为它似乎正在拉扯...
  • 来自 github repo 的文件在 Chrome 和 Firefox 中正常工作,所以我将其标记为正确。
猜你喜欢
  • 2013-05-19
  • 2015-01-27
  • 2018-12-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-03-24
  • 2016-04-04
  • 2013-10-16
相关资源
最近更新 更多