前端引入一种后缀名为.ttf
的字体,并在css文件中设置该字体,但是页面中并没有显示新引入的字体:
@font-face {
font-family: 'myFont';
src: url('./my-font.ttf') format('ttf');
font-weight: 600;
font-style: normal;
}
.my-font {
font-family: 'myFont';
color: red;
}
原因:后缀名为.ttf
的字体的format()
不是ttf
,而是 truetype,改成如下就行了:
@font-face {
font-family: 'myFont';
src: url('./my-font.ttf') format('truetype');
font-weight: 600;
font-style: normal;
}
.my-font {
font-family: 'myFont';
color: red;
}