css @ font-face不工作 [英] css @font-face doesn't work
问题描述
我需要在我的网页中用thte @ font-face设置一个字体,但是我不能正常工作:这是我的css文件的内容
I need to set a font family in my web page with thte @font-face, but I can't make it work propertly: This is the content of my css file
@font-face {
font-family: knockout;
src: url('../fonts/knockoutHTF27.ttf');
}
body {
font-width: normal;
font-size: 20px;
font-family: knockout !important;
color: #223041;
text-align: center;
}
我在两台不同的电脑上尝试过相同的代码,它工作在pefercty其中一个,但不工作在另一个。
I've tried the same code in two diferent computers and it works pefercty in one of them but doesn't work in the other. What could be wrong?
推荐答案
您应该尝试使用完全嵌入和所有引号。它会清除不同浏览器/操作系统上可能出现的故障。
You should try with full embedding, with all the quotation marks. It clears possible malfunctions on different browsers/OS.
@font-face {
font-family: 'MyWebFont';
src: url('webfont.eot'); /* IE9 Compat Modes */
src: url('webfont.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
url('webfont.woff') format('woff'), /* Modern Browsers */
url('webfont.ttf') format('truetype'), /* Safari, Android, iOS */
url('webfont.svg#svgFontName') format('svg'); /* Legacy iOS */
}
>
Then, use it like this:
body {
font-family: 'MyWebFont', Fallback, sans-serif;
}
如上一个答案所述,如果需要,可以使用 http://www.fontsquirrel.com/ 或网络上的其他字体生成器服务之一,以获取所有需要的字体格式。
As mentioned in a previous answer, if needed, you can use http://www.fontsquirrel.com/ or one of other font-face generator services on the web, to get all needed font formats.
这篇关于css @ font-face不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!