css - Google Web Font 没有在 Angular 中使用?

标签 css angular sass angular-cli

我使用 angular-cli 设置了一个 Angular 元素。我想将 Roboto 字体与我的网站捆绑在一起,所以我的做法是在我的 styles.scss 中声明它

/* You can add global styles to this file, and also import other style files */
@import url('https://fonts.googleapis.com/css?family=Roboto');

// Set Global Font
body {
  font-family: 'Roboto', sans-serif;
  margin: 0;
}

但是,字体似乎默认为 sans-serif 而不是 Roboto。我尝试在 index.html 中添加一个链接,同样的效果。

附言不确定是否相关,但我还添加了 Material Icons

// Import Material Icons
@font-face {
  font-family: 'Material Icons';
  font-style: normal;
  font-weight: 400;
  src: local('Material Icons'),
       local('MaterialIcons-Regular'),
       url('../node_modules/material-design-icons/iconfont/MaterialIcons-Regular.woff2') format('woff2'),
       url('../node_modules/material-design-icons/iconfont/MaterialIcons-Regular.woff') format('woff'),
       url('../node_modules/material-design-icons/iconfont/MaterialIcons-Regular.ttf') format('truetype');
}

在同一个文件中,这会以某种方式对元素产生影响吗?

最佳答案

由于您正在处理 @angular/cli 元素,我怀疑 .scss 文件中的链接是否有效。

通过npm安装roboto-fontface并链接到angular-cli.json的styles数组中

npm install roboto-fontface --save

在 angular-cli.json 样式数组 'apps[0].styles' 添加以下内容

    "styles": [
      ...
      "../node_modules/roboto-fontface/css/roboto/roboto-fontface.css"
      ...
    ]

然后,npm start 并尝试样式

关于css - Google Web Font 没有在 Angular 中使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42435942/

相关文章:

html - 文本的背景颜色。之间的空间。线条宽度相同。在线填充

jquery - 尽管代码相同,但在不同位置切换面板

javascript - Angular 2 : insert component into a certain position

css - SASS 嵌套结构搞乱了@media 查询的优先级

html - 悬停不适用于 SVG 路径的未填充区域

html - CSS 子选择器模式

javascript - jQuery 工具 - 垂直滚动条中的一项太长

html - 简单的 HTML 看起来很不靠谱?

javascript - Angular 单元测试: unable to change property value after DOM click

node.js - 如何在angular中使用pg Node 包