如何在React JS中使用Google Fonts API?

问题描述

我试图在我的React项目中设置Google字体,但无法覆盖React的原始字体系列。

在完成一些教程之后,我将想要的字体家族插入了index.css

body {
  /* margin: 0;
  font-family: -apple-system,BlinkMacSystemFont,'Segoe UI','Roboto','Oxygen','Lemonada'
    'Ubuntu','Cantarell','Fira Sans','Droid Sans','Helvetica Neue',sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale; */
  font-family: 'Lemonada',cursive;
}

出于测试目的,我评论了原始字体。

但是原始字体不会被覆盖:

enter image description here

如果我检查文件,则会看到以下内容:

enter image description here

如您所见,所有注释的字体仍然存在,除了index.css中不存在的许多其他内容。显然它来自某个style.css文件,但是我不知道在哪里可以找到它。

如果我取消选中此样式,则会得到我想要的字体系列:

enter image description here

enter image description here

当然,我还将api添加到了我的index.html文件中。

<link href="https://fonts.googleapis.com/css2?family=Lemonada:wght@300&display=swap" rel="stylesheet">

我希望能够添加新的字体系列,或者至少覆盖原始字体系列。

我在做什么错了?

解决方法

确保l = ['49275','49287','69674','43924'] x = '49375' listy = [0] * len(l) for i,el in enumerate(l): for n in range(len(x)): if el[n] != x[n]: break listy[i] += 0.2 已在CSS文件之前加载。

也尝试将行更改为

<link href="https://fonts.googleapis.com/css2?family=Lemonada:wght@300&display=swap" rel="stylesheet">
,

我不断挖掘,发现了两种可能的解决方案:

remote_directory "/opt/info" do source [/*.txt/] owner 'root' group 'root' mode '0640' end 而不是使用1-,而是将字体系列直接放在与我要使用字体的组件相对应的css文件中,在这种情况下,这是文件{{1 }}。

index.css我发现了这个库,它也可以工作,并且看起来非常不错:https://www.npmjs.com/package/react-google-font-loader

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...