I am trying to change the background color of the container of p-card
component.
For context, I am brute forcing to change some styling in primeng components just to see if I will be able to have that flexibility just before diving into a project. The problem is, sometimes I can style the components the way I want to, sometimes I don’t know how and why the specifity in css don’t work.
This works:
p-button {
margin: 1rem;
}
But not this:
p-card div.p-card-body {
background-color: purple;
}
Even specifying !important
dont work.
Versions: Angular 18
&& PrimeNG 18.0.0-beta.2
Can anyone help? I have not seen some good guide on the internet.
2
Answers
One way to increase the specificity in CSS when
!important
doesn’t work is to repeat the class name, you can try this:in the primeng library you can make use of the [style] property to change the color or even inject style to the plugin
ie,
here the
[style]="{ background: 'purple' }"
will do the action needed here.im adding a stackblitz example here for clarity here