如何在角度2中包含自定义.otf字体

时间:2018-03-08 16:27:37

标签: angular fonts sass

我想在我的网络应用中包含一堆自定义字体。我已将它们放在src中的assets / fonts文件夹中,但我不确定如何将它们实际包含在我的项目中

我在styles.scss中添加了以下内容,它编译但不会更改我的字体:

body {
  font: Custom;
}

@font-face {
  font-family: Custom;
  src: url('assets/fonts/Custom.otf') format('opentype');
}

1 个答案:

答案 0 :(得分:2)

找到了解决方案

自定义需要在引号中,并且!对于覆盖当前字体非常重要

body {
  font-family: 'Custom', Fallback, sans-serif !important;
}

@font-face {
  font-family: 'Custom';
  src: url('assets/fonts/Custom.otf') format('opentype');
}