简体   繁体   English

如何将本地/自定义 fonts 添加到反应 js 项目?

[英]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。

index.js索引.js

index.css index.css

app.scss应用程序.scss

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM