简体   繁体   English

覆盖包中的css样式

[英]Overriding css styles of a package in angular

Angular cli automatically loads css files those are in node_module directory. Angular cli自动加载位于node_module目录中的css文件。 I am using @swimlane/ngx-dnd and it has css style. 我正在使用@ swimlane / ngx-dnd ,它具有CSS样式。 But I want to use bootstrap styles for my components. 但是我想对我的组件使用引导样式。 What's standard way for doing this ? 这样做的标准方法是什么?
Appreciate any idea and helps. 感谢任何想法并提供帮助。

If you want to override a package's styles, you can just provide overrides in your own stylesheet or component stylesheet with the same or more specific style definition. 如果要覆盖包的样式,则只需在自己的样式表或组件样式表中使用相同或更特定的样式定义来提供覆盖。 Your definition will need to match their style, but must be loaded after their style and/or be more specific so that your style applies correctly. 您的定义将需要与它们的样式匹配,但必须在其样式之后加载和/或更具体,以便正确应用样式。

If you want to exclude their style sheets you will need to use some sort of plugin for webpack to Ignore the css files in the package directory. 如果要排除它们的样式表,则需要为Webpack使用某种插件来忽略package目录中的css文件。

I'd recommend the first approach. 我建议第一种方法。

If the package you are using creates dynamic markup along with the styling, you may need to change your component encapsulation so that the component you are using can successfully apply your styles to the generated dom elements. 如果您使用的包与样式一起创建了动态标记,则可能需要更改组件的封装,以便您使用的组件可以将样式成功地应用于所生成的dom元素。

In your app.component.ts, add: 在您的app.component.ts,添加:

@Componenent({
   encapsulation:ViewEncapsulation.None,
   styleUrls:[''],  // Add your bootstrap css files
   templateUrl: ....
})

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

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