如何引用字体包

在开发中会遇到需要导入一些特殊的字体包

如果ui只给了ttf包可以通过https://www.font2web.com/这个网址来转换为各个格式的字体文件,因为不同的文件针对不同的浏览器,如果只有单一的ttf可能会有兼容问题

新建一个css文件并引入相关字体文件

@charset "UTF-8";

@font-face {
  font-family: "自定义的字体名";
  src: url("字体文件.woff2") format("woff2"),
       url("字体文件.woff") format("woff"),
       url("字体文件.ttf") format("truetype"),
       url("字体文件.eot") format("embedded-opentype"),
       url("字体文件.svg") format("svg");
  font-weight: normal;
  font-style: normal;
}

使用时只需要

import  新建的css文件

就可以在css代码中使用

font-family: 自定义的字体名;
原文地址:https://www.cnblogs.com/wangxirui/p/15494692.html