我想在我的mat-table中选择它时更改行的颜色。
我已经知道了background color
,但如果我在桌子上选择它,我无法改变white
的行颜色
你可以添加你的默认类,比如class="table-row"
和tabindex="1"
到<mat-row>
<mat-row class="table-row" tabindex="1"
*matRowDef="let row; columns: displayedColumns;"></mat-row>
并且,在css文件中写
.table-row:focus {
background: tomato;
outline: none;
}
.table-row:focus mat-cell {
color: white;
}
Stackblitz Demo highlighting table row on click with changed color
你能试试这个:
在HTML中:
<mat-row [ngClass]="{'selected': selectedRowIndex == row.id}">
</mat-row>
在css中:
.selected {
color: white;
}