Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I override the style of primeng components?

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?

like image 740
Pardeep Jain Avatar asked Oct 19 '16 12:10

Pardeep Jain


People also ask

Is ng deep deprecated?

Both APIs ::ng-deep and /deep/ are deprecated and will eventually be removed in the future.

Is there a way to style primeng's components within a component?

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.

Is it possible to override the primeng style in angular?

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.

How to override inline styles with the !important rule?

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.

Is there a way to style A P-menu in primeng?

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.


2 Answers

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>
like image 105
ZR87 Avatar answered Sep 17 '22 08:09

ZR87


Try using

:host >>> .ui-dropdown-item {...}

You won't need any surrounded div or adding the styles to the main style.css.

like image 34
jcdsr Avatar answered Sep 17 '22 08:09

jcdsr