【问题标题】:loading a local woff2 file in a CSS file isn't working在 CSS 文件中加载本地 woff2 文件不起作用
【发布时间】:2020-09-25 19:44:00
【问题描述】:

我正在尝试在 CSS 文件中加载 woff2 字体文件。但是我不断收到错误消息,说找不到该文件。但路径是正确的。
我的 CSS 文件:

@font-face {
  font-family: 'Material Icons';
  font-style: normal;
  font-weight: 400;
  src: url("C:\Users\win10\Desktop\Electron_Projects\EnderFramework\_themes\_default\fonts\material_icons.woff2") format('woff2');
}

icon, icons{
  font-family: 'Material Icons';
  font-weight: normal;
  font-style: normal;
  display: inline-block;
  line-height: 1;
  text-transform: none;
  letter-spacing: normal;
  word-wrap: normal;
  white-space: nowrap;
  direction: ltr;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: 'liga';
}

这是我不断收到的错误:
加载资源失败:net::ERR_FILE_NOT_FOUND file:///C:/Userswin10%C3%9Esktop%0Electron_Projects%0EnderFramework_themes_default%0Fontsmaterial_icons.woff2:1

【问题讨论】:

    标签: html css web fonts


    【解决方案1】:

    尝试指定一个不完整的文件路径,相对。

    @font-face {
      font-family: 'Material Icons';
      font-style: normal;
      font-weight: 400;
      src: url("..\fonts\material_icons.woff2") format('woff2');
    }
    

    另外,使用反斜杠可能会导致错误。

    @font-face {
      font-family: 'Material Icons';
      font-style: normal;
      font-weight: 400;
      src: url("../fonts/material_icons.woff2") format('woff2');
    }
    

    【讨论】:

    • 就我而言,我必须使用完整路径形式。所以这对我没有帮助。
    • @enderadel 你试过“翻转”斜线吗? src: url("C:/Users/win10/Desktop/Electron_Projects/EnderFramework/_themes/_default/fonts/material_icons.woff2") format('woff2');
    猜你喜欢
    • 1970-01-01
    • 2012-12-02
    • 2017-05-24
    • 1970-01-01
    • 1970-01-01
    • 2014-07-28
    • 1970-01-01
    • 2015-03-04
    相关资源
    最近更新 更多