What is Best way to override the style of primeng components?

后端 未结 6 1487
南方客
南方客 2020-12-02 17:02

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

6条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-02 17:52

    The only way to do this that I'm aware of is by using the :host and ::ng-deep, called "shadow piercing CSS combinators"

    You could enable ViewEncapsulation.Native to employ the Shadow DOM, but my understanding is its not widely supported yet. Chrome and Safari support it, I think Firefox might be there, but IE is still a ways off from adding the feature.

    Good article about View Encapsulation in angular here, and a good post about shadow piercing here. You can also view the documentation on this from the Angular team here

    In my application im using PrimeNG as well. Since I'm importing a primeNG component into, lets call it MyComponent, that means the styles applied to MyComponent will be encapsulated and wont apply to the primeNG UI elements im incorporating. Shadow piercing combinators allow me to "pierce" through Angular's "emulated" Shadow DOM to style the PrimeNG stuff, but it seems a little messy and not ideal. I've looked for a way around this but I'm not aware of anything.

提交回复
热议问题