I am not able to override text-align: center in mat-sort-header
I have created a new class and added text-align: right in that class but it is not working.
It is taking the text-align: center from mat-sort-header and not allowing to text-align: right.
2
Answers
Mb u need to use !important for your class?
I assume you want to align the contents of the header to the right. It won’t work by changing the
text-align
property. If you inspect the element in the DOM, you’ll see that themat-sort-header
directive puts an additional flex container inside the header, which contains both the header text and the sort arrow. To alight the content to the right, you have to applyjustify-content: end;
on that container.You can add additional class on the header:
And define the class in the global
styles.scss
:Or you can just set it globally without adding new class:
Note that since this happens inside a new component injected through a directive, this needs to happen in global styles. Alternatively you can use
::ng-deep
and place it in your component style, but it will still be promoted to global style (read here), so the effect is pretty much the same.Here’s an stackblitz based on the example from the official docs.