css - 无法在 Angular cli 新元素中加载样式

标签 css angular google-chrome angular-cli

我刚刚使用 angulari cli 创建了一个新元素。

当我尝试在 index.html 中包含 styles.css 文件时

<link rel="stylesheet" type="text/css" href="styles.css">

我在 Chrome 的开发工具网络选项卡中收到了这个:

Refused to apply style from 'http://localhost:4200/styles.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.

知道如何解决这个问题吗?我在本地使用 ng serve

运行

enter image description here

我也尝试添加

./styles.css
/styles.css
styles.css

最佳答案

当我们创建 angular-cli 元素时,styles.css 将应用默认值,您可以在 .angular-cli.json 中看到它

app: {
styles:[
  "styles.css"
]

如果您需要,您可以在此处根据您的元素添加更多样式。

关于css - 无法在 Angular cli 新元素中加载样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48817278/

相关文章:

Angular 无法在 Chrome 中运行

css - 如何在 CSS Sprite 中缩放图像

html - 垂直扩展台

css - 使用未导入到它们的 css 文件来 react 组件

html - 如何使用 css 创建此边框

Angular 渲染的 DOM html 自定义属性

javascript - Angular 2 QuickStart &lt;script/> 失败

javascript - Angular 2 : Directives: capturing click event on children

google-chrome - 自 v38 起,Chrome 扩展程序无法再从 HTTP URL 加载,有解决方法吗?

google-chrome - 为什么 View Source 会发出新的 HTTP 请求?