Webfont无法在Chrome和Firefox中运行

时间:2015-04-13 15:02:49

标签: css google-chrome firefox font-face

所以,我试图将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

2 个答案:

答案 0 :(得分:1)

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

<强>更新

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

更新2

刚刚从font squirrel下载了字体,它似乎也不适用于firefox或chrome。

答案 1 :(得分:1)

所以我在fontsquirrel上找到了这个字体,我假设你下载了它。

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

Font not working Demo not working

我会尝试在其他地方为该文件找到一个镜像并使用它,或者它可能只是直接打破了,你可能需要找到另一个选项。

相关问题