I want to overright the style of primeng components as per component level not for whole app. Either I have to change the style in main theme.css
file or inline style, but seems inline not works sometimes as expected. As example, I have to use
<p-dropdown [options]="cities" formControlName="selectedCity"></p-dropdown>
And I have to change the style of class ui-dropdown-item
class name as per documentation.
I need same component with two diff style what is the correct approach for doing this?
Both APIs ::ng-deep and /deep/ are deprecated and will eventually be removed in the future.
The only way I'm aware of to style PrimeNG's (or any other external component library such as ng-bootstrap) stuff within your component is to either: and it would work, overriding the default PrimeNG style, since encapsulation is turned off.
and it would work, overriding the default PrimeNG style, since encapsulation is turned off. With ViewEncapsulation.Emulated (Angular's default setting) in order to get the style above to work you have to "pierce" the view encapsulation as i mentioned.
When an important rule is used on a style declaration, this declaration will override any other declarations. When two conflicting declarations with the !important rules are applied to the same element, the declaration with a greater specificity will be applied. Let’s see how you can use the !important declaration to override inline styles.
With ViewEncapsulation.None you could write a style for p-menu like: .ui-menu {margin:0;} and it would work, overriding the default PrimeNG style, since encapsulation is turned off.
Since >>>
is deprecated have to use ::ng-deep
instead. With material2 v6
and primeng v5.2.*
:host { ::ng-deep .prime-slider-override { background-color: #26A3D1; background-image:none; border:none; color:white; .ui-slider-range { background: red; } } }
<p-slider [(ngModel)]="rangeValues" styleClass="prime-slider-override"></p-slider>
Try using
:host >>> .ui-dropdown-item {...}
You won't need any surrounded div or adding the styles to the main style.css
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With