CSS导入otf字体

10

大家好,我在使用otf字体文件时遇到了一些问题。

main.css

@font-face {
    font-family: 'testfont';
    src: url('fonts/test.otf');
}

.fonttest {
    font-family: 'testfont';
}

main.html

<p class="fonttest">TESTtest</p>

但是当我尝试启动主页时,它仍然显示HTML的标准字体。当我在我的浏览器Opera和Chrome上使用检查器时,它显示字体已被接受。


你应用了哪种字体? - Bhargav Chudasama
你可以在开发工具中验证字体URL是否正确,并且已正确传输到客户端吗?另外,你使用的Opera版本是否支持OTF字体格式? - Constantin Groß
当我在我的浏览器Opera和Chrome上使用检查器时,它显示字体已被接受 - 不,它并没有。这只是表明您指定了某个字体系列名称。 - CBroe
2个回答

20

使用此语句;

@font-face {
    font-family: testfont;
    src: url("fonts/test.otf") format("opentype");
}

1
值得注意的是,format("otf")将无法正常工作。 - Chris Hayes

0

你可以使用 @font-face 来实现自己的 OTF 字体,例如:

@font-face {
    font-family: testfont;
    src: url("fonts/test.otf") format("opentype");
}

@font-face {
    font-family: testfont;
    font-weight: bold;
    src: url("fonts/test.otf") format("opentype");
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接