Reputation: 1
I have a component using angular material 9.
There are 3 tabs in my component.
I need Completed tab label background color as green, Overdue label background color as red and Extended background color as brown.
Angular Material customize tab
I have tried this solution but it applies single color for all tabs. My expectation is one color per one particular tab. Please refer the below attached image.
Upvotes: 0
Views: 1727
Reputation: 3160
you can use the nth of type selector to target the tab labels and set the background alternatively you can set aria-labels for individual tabs and target the label names
Example with nth of type selector
::ng-deep {
.mat-tab-label {
&:nth-of-type(1){
background-color: green;
}
&:nth-of-type(2){
background-color: red;
}
&:nth-of-type(3){
background-color: brown;
}
}
}
Example with aria-label
<mat-tab-group>
<mat-tab aria-label="completed" label="Completed"> Content 1 </mat-tab>
<mat-tab aria-label="overdue" label="Overdue"> Content 2 </mat-tab>
<mat-tab aria-label="extended" label="Extended"> Content 3 </mat-tab>
</mat-tab-group>
::ng-deep {
.mat-tab-label {
&[aria-label="completed"] {
background-color: green;
}
&[aria-label="overdue"] {
background-color: red;
}
&[aria-label="extended"] {
background-color: brown;
}
}
}
Upvotes: 1