【问题标题】:Laravel 8 add downloaded fonts and use themLaravel 8 添加下载的字体并使用它们
【发布时间】:2021-08-13 23:33:31
【问题描述】:

我刚刚升级到 laravel 8,需要使用字体建立一个网站。我已经下载了字体并将它们放在字体文件夹中的资源文件夹中。之后我将它们添加到我的css中,但它似乎不起作用。我错过了一步,是否需要先编译bij webpack?我做错了什么?

字体: https://fontsgeek.com/fonts/Jot-Regular https://fonts.google.com/specimen/Roboto

style.scss:

@font-face {
    font-family: JotRegular;
    src: local('/fonts/JotRegular.ttf');
    font-weight: normal;
    font-style: normal;
}

@font-face {
    font-family: Roboto;
    src: local('/fonts/Roboto-Regular.ttf');
    font-weight: normal;
    font-style: normal;
}

h2{
    font-size: 2.2rem;
    font-family: JotRegular;
}

【问题讨论】:

  • 你用 npm 编译你的资产了吗?在开发过程中使用npm run watch

标签: laravel webpack sass fonts compilation


【解决方案1】:

使用local 加载字体会绕过 webpack 中的字体编译。所以字体不会自动复制到公用文件夹中,字体必须手动复制到正确的路径,不推荐。要启用自动字体操作,您可以使用:

@font-face {
    font-family: JotRegular;
    src: url('../fonts/JotRegular.ttf'); // remember that font file path must be relative to the current css file. not the final compiled folder
    font-weight: normal;
    font-style: normal;
}

这样webpack会自动将字体文件复制到最终编译的目录public中。此外,自动文件版本控制将通过这种方式进行。

【讨论】:

  • 我将填充物放在正确的文件夹中并更改了 url 并且 url 下的波浪形红线消失了,它工作了。非常感谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-12-25
  • 2022-01-14
  • 2013-04-02
  • 1970-01-01
  • 2016-12-13
  • 2021-07-18
  • 2020-03-15
相关资源
最近更新 更多