How to use Google fonts in React.js?

前端 未结 12 777
既然无缘
既然无缘 2020-12-02 18:06

I had built a website with React.js and webpack.

I want to use Google fonts in the webpage, so I put the link in the section.

Go

12条回答
  •  [愿得一人]
    2020-12-02 18:46

    In some cases your font resource maybe somewhere in your project directory. So you can load it like this using SCSS

     $list: (
          "Black",
          "BlackItalic",
          "Bold",
          "BoldItalic",
          "Italic",
          "Light",
          "LightItalic",
          "Medium",
          "MediumItalic",
          "Regular",
          "Thin",
          "ThinItalic"
        );
        
        @mixin setRobotoFonts {
          @each $var in $list {
            @font-face {
              font-family: "Roboto-#{$var}";
              src: url("../fonts/Roboto-#{$var}.ttf") format("ttf");
            }
          }
        }
    @include setRobotoFonts();
    

提交回复
热议问题