我试图在我的项目中包括一些自定义字体,但没有成功。
注:我使用的是角-cli:角-cli@1.0.0-beta.21
src/styles.css
@字体-face{字体-系列:“Roboto-正则”;src: url("./assets/fonts/Roboto-Regular.tff");}.scss中使用它
字体-家庭:“机器人-常规”;1. If I add the font-face definition in `app.component.scss` I get 404 error as welljquery.js:2 GET http://localhost:4200/assets/fonts/Roboto-Regular.tff 404
对如何包含我的Roboto-Regular.tff字体有什么想法吗?
发布于 2017-02-17 12:48:53
通过搜索到达这里的人:
使用npm安装:
npm install roboto-fontface --save
在.angular-cli.json (apps[0].styles)中添加样式:
"styles": [
"styles.css",
"../node_modules/roboto-fontface/css/roboto/roboto-fontface.css"
],就这样!
编辑:因为角6,这个文件被称为angular.json而不是angular-cli.json。添加字体的方式仍然和以前一样。
发布于 2017-01-03 15:25:46
你试过使用https://fonts.google.com的googlefont吗?
在styles.css中:
@import url('https://fonts.googleapis.com/css?family=Roboto');然后在styles.css或您需要的任何地方使用字体系列:
body, html {
font-family: 'Roboto';
}我在我的项目中使用了这个,它运行得很好。
发布于 2018-01-27 21:00:45
如果使用SCSS,您可以:
安装roboto-fontface
npm install roboto-fontface --save导入您的styles.scss文件
@import '~roboto-fontface/css/roboto/roboto-fontface.css';
body {
font-family: Roboto, Helvetica, Arial, sans-serif;
}https://stackoverflow.com/questions/40884511
复制相似问题