Angular 4 Material表突出显示一行并更改选定的行颜色

问题描述 投票:0回答:2

我想在我的mat-table中选择它时更改行的颜色。 我已经知道了background color,但如果我在桌子上选择它,我无法改变white的行颜色

angular angular-material material
2个回答
0
投票

你可以添加你的默认类,比如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


0
投票

你能试试这个:

在HTML中:

  <mat-row [ngClass]="{'selected': selectedRowIndex == row.id}">
    </mat-row>

在css中:

.selected {
    color: white;
}
© www.soinside.com 2019 - 2024. All rights reserved.