CSS中资产的绝对路径URL

时间:2020-07-11 02:05:09

标签: css reactjs

为什么该资源(字体)的绝对路径不起作用,而相对路径却起作用?

<body>
  hello friend
</body>
<style type="text/css">
  @font-face {
    font-family: 'Gilroy';
    /* src: url("../src/styles/assets/Gilroy.otf"); */
    src: local('Gilroy')
      url('/Users/username/dev-env/test-react/app/src/styles/assets/Gilroy.otf');
  }
  body {
    font-family: Gilroy;
  }
</style>

编辑:这是React / Babel / Webpack的问题。 enter image description here

1 个答案:

答案 0 :(得分:1)

您在,之后缺少local()

<style type="text/css">
  @font-face {
    font-family: 'Gilroy';
    src: local('Gilroy'),
      url('/Users/username/dev-env/test-react/app/src/styles/assets/Gilroy.otf');
  }
  body {
    font-family: Gilroy;
  }
</style>

请参见@font-face examples

相关问题