简体   繁体   English

将 css 样式应用于我的 angular 应用程序中的所有primeng 对话框

[英]Apply css style to all primeng dialogs in my angular app

I am using prime ng dialog all over my angular application.我在我的 angular 应用程序中使用了主要的 ng 对话框。 I can change each specific dialog style by using ng-deep.我可以使用 ng-deep 更改每个特定的对话框样式。 For eg I have contact us page for which I have these files:例如,我有联系我们页面,我有这些文件:

contact.html
contact.component.ts
contact.css

So I place the below css in contact.css and it changes the contact us dialog title bar color.所以我将下面的 css 放在 contact.css 中,它改变了联系我们对话框标题栏的颜色。

:host ::ng-deep .ui-dialog .ui-dialog-titlebar{
    background-color: red
}

I want to do this for all the dialogs in my application, how can I do this?我想对应用程序中的所有对话框执行此操作,我该怎么做? I placed the same css in style.css file in src folder and it didn't work.我在 src 文件夹中的 style.css 文件中放置了相同的 css,但它不起作用。

So angular components by default employ a very handy strategy of Style Encapsulation which makes it so that styles don't bleed out into other components and cause unwanted effects.所以 angular 组件默认采用一种非常方便的样式封装策略,这使得样式不会渗入其他组件并导致不需要的效果。

You can utilize ng-deep like you have to allow styles defined within it to be inherited by child components of where it's specified.您可以使用ng-deep就像您必须允许其中定义的样式被指定位置的子组件继承一样。

However for things to be globally inherited you'll want to define them highest up in the order of inception so those styles cascade down to selectors below.但是,对于全局继承的事物,您需要按照开始的顺序将它们定义在最高位置,以便这些样式级联到下面的选择器。 In a default angular application that's not using SCSS or another pre-processor one of the easiest ways to do this is to add them to one of the first files initialized that hosts the child components such as index.html or app.component to allow components initialized afterwards to inherit them when they're rendered.在不使用 SCSS 或其他预处理器的默认 Angular 应用程序中,最简单的方法之一是将它们添加到初始化的第一个文件中,该文件承载子组件(例如index.htmlapp.component以允许组件之后初始化以在渲染时继承它们。

Hope this helps, cheers!希望这有帮助,干杯!

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

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