[英]How to add local / custom fonts to a react js project?
I want to add some custom / local fonts to my react project, can anyone tell me the method to use it inside react project?我想在我的反应项目中添加一些自定义/本地 fonts,谁能告诉我在反应项目中使用它的方法?
Below I have added some ss of my code which is not working.下面我添加了一些无法正常工作的代码 ss。
Thanks谢谢
You import the bold
font in your index.js
but you set the book
font in your App.scss
.您在
index.js
中导入bold
字体,但在App.scss
中设置book
字体。 Also try to add !important
when setting the font-family
on the body:在主体上设置
font-family
时,也尝试添加!important
:
html,
body {
font-family: "CooperHewitt-Bold" !important;
}
Using @font-face
:使用
@font-face
:
/* index.css */
@font-face {
font-family: "CooperHewitt-Bold";
src: local("CooperHewitt-Bold"),
url(./fonts/CooperHewitt-Bold.otf) format("opentype");
}
Make sure to import index.css
inside index.js
:确保在
index.js
中导入index.css
:
import './index.css';
// ...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.