简体   繁体   English

Angular (13) 材质 - 覆盖 CSS 文件不起作用

[英]Angular (13) Material - override CSS file doesn't work

I have a simple Angular (13) application with Material.我有一个带有 Material 的简单 Angular (13) 应用程序。 I've created a CSS file that is meant for overriding some of the Material styles, and imported it into styles.scss.我创建了一个 CSS 文件,该文件旨在覆盖一些材料 styles,并将其导入 styles.scss。 This import is the last line of this file.此导入是此文件的最后一行。 Yet, none of the CSS definitions in the external file seem to actually override the existing styles from Material.然而,外部文件中的 CSS 定义似乎都没有真正覆盖 Material 中现有的 styles。 When I place these definitions directly in styles.scss, they work.当我将这些定义直接放在 styles.scss 中时,它们就起作用了。 What is the difference between importing CSS definitions from a file and placing them directly, in this case?在这种情况下,从文件导入 CSS 定义并直接放置它们有什么区别? Am I missing something here?我在这里错过了什么吗?

To import css to an scss file, you should import it without the extension like this.要将css导入到scss文件,您应该像这样在不带扩展名的情况下导入它。

@import "path/to/file/file_name_without_extension"

If you import that with extension如果您使用扩展名导入它

@import "path/to/file/file_name.css"

it won't work as it gets translated to它不会工作,因为它被翻译成

@import url(path/to/file/file_name.css);

Merged PR from SASS repo: Implement raw css imports从 SASS 回购合并 PR:实施原始 css 导入

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM