Webfont 在 Chrome 和 Firefox 中不工作
Webfont Not Working in Chrome and Firefox
所以,我正在尝试将 StateFace 字体导入到我正在使用的 Web 应用程序中。我正在使用以下 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
您在 CSS 中缺少 woff 源代码调用。您必须添加 woff 源以获得 chrome 支持。在 Whosebug. I reccommend using Font Squirrel Web Font Generator 上阅读此答案。只需上传您的字体,它就会生成跨浏览器功能所需的所有 CSS。
更新:
另一个可能的问题是 Bootstrap less 可能会覆盖您的样式,因为您的 CSS 选择器不够具体。
更新 2:
刚刚从 font squirrel 下载了字体,似乎它在 firefox 或 chrome 中对我来说也不起作用。
所以我在 fontsquirrel 上找到了字体,我假设你是从那里下载它的。
Fontsquirrel 自己的演示文件在 Chrome 中对我不起作用,并且它们的 TTF 格式在 windows 中不起作用:
我会尝试在其他地方找到该文件的镜像并使用它,或者它可能直接损坏了,您可能必须找到另一个选项。
所以,我正在尝试将 StateFace 字体导入到我正在使用的 Web 应用程序中。我正在使用以下 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
您在 CSS 中缺少 woff 源代码调用。您必须添加 woff 源以获得 chrome 支持。在 Whosebug. I reccommend using Font Squirrel Web Font Generator 上阅读此答案。只需上传您的字体,它就会生成跨浏览器功能所需的所有 CSS。
更新:
另一个可能的问题是 Bootstrap less 可能会覆盖您的样式,因为您的 CSS 选择器不够具体。
更新 2:
刚刚从 font squirrel 下载了字体,似乎它在 firefox 或 chrome 中对我来说也不起作用。
所以我在 fontsquirrel 上找到了字体,我假设你是从那里下载它的。
Fontsquirrel 自己的演示文件在 Chrome 中对我不起作用,并且它们的 TTF 格式在 windows 中不起作用:
我会尝试在其他地方找到该文件的镜像并使用它,或者它可能直接损坏了,您可能必须找到另一个选项。