In my opinion, the solutions offered for this particular problem are excessively rigid in their approach. I encountered a similar issue where I needed to dynamically adjust certain CSS properties of mat-sort-header-container
.
My solution was inspired by Vega's answer but with a slight twist in how styles are applied:
::ng-deep .mat-sort-header-container{
justify-content: inherit;
/* other inheritable properties */
}
This allows the parent element to style mat-header-cell
, as specified in your HTML code. Any styles provided in both mat-header-cell
and within the ng-deep
selector (which inherits from its parent) will be cascaded down the hierarchy while disregarding any other styles.