首页 > 解决方案 > 在 scss 中导入字体变体 - React

问题描述

我是新手,css所以我有点困惑。这是我在index.scss文件中所做的

@import url('https://fonts.googleapis.com/css?family=Nunito+Sans:400,400i,700,800,800i,900i&display=swap');

body {
  font-family: 'Nunito Sans', sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

我想做所有的段落Nunito Sans Bold Italic。我怎么能在特定的文件中做到这一点说components/link.js

标签: cssreactjssassgoogle-fonts

解决方案


要使所有使用 Nunito Sans 的段落以粗体和斜体设置样式,您首先需要定位每个p元素,然后添加您需要的字体系列和字体样式。例如:

p {
  font-family: 'Nunito Sans', sans-serif;
  font-weight: bold;
  font-style: italic;
}

如果您只想在该特定组件中使用此 css,请创建一个单独的 scss 文件并将其仅导入该组件,例如:

@import './link-style.scss';


推荐阅读