使用@ font-face覆盖默认字体

时间:2019-06-01 11:36:57

标签: css fonts font-face

我们要使用@ font-face修改HTML中的默认字体

@font-face {
    font-family: Times;
    font-style: normal;
    font-weight: 400;
    src: local('serif');
}

在上面的代码中,我们想将Times字体覆盖为衬线,但是上面的代码无法正常工作,并且Times字体一直在使用,而不是衬线。

1 个答案:

答案 0 :(得分:1)

尝试以下示例,它对我有用-https://jsfiddle.net/gbk4rLw3/16/。但是,如果您尝试切换诸如serif或sans-serif之类的通用字体类型的字体,则似乎不起作用,但是其他任何网络安全字体似乎都可以起作用。

测试代码也在这里。

HTML

<div class="test">
TESTING
</div>

CSS

.test{
  font-family: Times;
}

@font-face {
    font-family: Times;
    font-style: normal;
    font-weight: 400;
    src: local("Impact"); /* Try replacing with Arial, Comic Sans MS, etc....*/
    }                          /*Doesn't seem to work with generic font types (serif,                                     sans-serif)*/

如果需要衬线字体,请尝试使用“ Courier New”。

相关问题