[英]Overriding a material CSS class in Angular component CSS
I have overridden some global material styles in an Angular component CSS file (not scss) like so:我在 Angular 组件 CSS 文件(不是 scss)中覆盖了一些全局材料 styles,如下所示:
.fixed-plugin .dropdown-menu {
left: -503px !important;
width: 500px;
}
This does work, however, it affects all references to these CSS classes in the component which is fine where is only one reference.这确实有效,但是,它会影响组件中对这些 CSS 类的所有引用,这很好,只有一个引用。
What I would really like to do is somehow create my own class and somehow inherit from the fixed-plugin.dropdown-menu
and then apply my overrides (change widths).我真正想做的是以某种方式创建我自己的 class 并以某种方式从
fixed-plugin.dropdown-menu
继承,然后应用我的覆盖(更改宽度)。 Then I can reference my own class in the only place I need it and the global material CSS remains untouched.然后我可以在唯一需要的地方引用我自己的 class 并且全局材料 CSS 保持不变。
Thanks谢谢
In your component styles use this :host::ng-deep.dropdown-menu
.在您的组件 styles 中使用这个
:host::ng-deep.dropdown-menu
。 It limits styles to your component and overrides global angular styles for your components inside.它将 styles 限制为您的组件,并为您的组件覆盖全局 angular styles。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.