angular-cli 如何添加全局样式? [英] angular-cli how to add global styles?

查看:36
本文介绍了angular-cli 如何添加全局样式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Sass 创建了一个全局样式表并将其放在 public/style/styles.scss 中.我只指定了背景色.

I created a global style sheet using Sass and put it in the public/style/styles.scss. I only specify a background color.

在索引中,我添加了一个链接:<link rel="stylesheet";href="style/styles.css">

In the index, I added a link to it: <link rel="stylesheet" href="style/styles.css">

背景颜色不适用于 body 标签.在检查 body 标签时,我可以看到背景颜色已应用但被 scaffolding.less:31

The background color does not work on the body tag. Upon inspecting the body tag I can see that the background-color was applied but overruled by scaffolding.less:31

我做错了什么?

推荐答案

从 CLI 的 beta.14 版本(使用 Angular 2.0 final)开始,可以在 angular-cli.json 中链接全局样式表 在样式"键下.这是对相对于 src/ 目录的文件的引用,默认情况下是 style.css.

As of the beta.14 release of the CLI (which uses Angular 2.0 final), a global stylesheet can be linked inside angular-cli.json under the "styles" key. This is a reference to a file relative to the src/ directory, which is style.css by default.

利用这种方法,您可以:

Leveraging this method you could:

  • 将全局样式复制到src/styles.css
  • 使用 CSS 导入将外部规则导入到 styles.css
  • 通过 angular-cli.json
  • 中的 apps[0].styles 属性添加更多全局样式
  • Copy the global styles into src/styles.css
  • Use CSS imports to import external rules into styles.css
  • Add more global styles via the apps[0].styles property in angular-cli.json

另见angular-中的全局样式cli 的维基.

See also Global Styles in angular-cli's wiki.

这篇关于angular-cli 如何添加全局样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆