小编Ale*_*low的帖子

如何使用样式化组件在 Reactjs 中导入本地字体?

import { createGlobalStyle } from "styled-components";

createGlobalStyle`
  @font-face {
    font-family: 'Segoe Pro Regular';
    font-style: normal;
    font-weight: normal;
    src: url('SegoePro-Regular.woff') format('woff');
}`
Run Code Online (Sandbox Code Playgroud)

之后我添加import "./components/GlobalStyles";到 index.js

我试图在某些组件中使用它,font-family: Segoe Pro Regular;但它不起作用


我也试过导入

import Font from "./SegoePro-Regular.woff"
import { createGlobalStyle } from "styled-components";

    createGlobalStyle`
      @font-face {
        font-family: 'Segoe Pro Regular';
        font-style: normal;
        font-weight: normal;
        src: url(${Font}) format('woff');
    }`
Run Code Online (Sandbox Code Playgroud)

javascript reactjs styled-components

3
推荐指数
1
解决办法
4745
查看次数

标签 统计

javascript ×1

reactjs ×1

styled-components ×1