CSS 更改角度材料表字体颜色
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/47529743/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Change angular material table font color
提问by valerossi46
I have an angular material design table component, and I can't achieve to change the font color of a selected row.
我有一个有角度的材料设计表组件,我无法实现更改选定行的字体颜色。
Here's a part of my HTML template:
这是我的 HTML 模板的一部分:
<mat-table #table [dataSource]="dataSource" matSort flex layout="row" layout-fill>
<ng-container matColumnDef="segmentName">
<mat-header-cell *matHeaderCellDef mat-sort-header> Segment </mat-header-cell>
<mat-cell *matCellDef="let element"> {{element.segmentName}} </mat-cell>
</ng-container>
<ng-container matColumnDef="bestRider">
<mat-header-cell *matHeaderCellDef mat-sort-header> KOM </mat-header-cell>
<mat-cell *matCellDef="let element"> {{element.bestRider}} </mat-cell>
</ng-container>
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
<mat-row *matRowDef="let row; columns: displayedColumns;" (click)="setSelectedRow(row)" [ngClass]="{'highlight': selectedRowIndex == row.id}"></mat-row>
</mat-table>
And a part of css:
和 css 的一部分:
.highlight{
color: white;
background: #673AB7;
}
If I click on a row, the background color of the "highlight" style is correctly applied, but the font color is always black. Could someone help me ? Thanks !!
如果我单击一行,正确应用了“突出显示”样式的背景颜色,但字体颜色始终为黑色。有人可以帮助我吗?谢谢 !!
回答by mohit uprim
You have to override the color of mat-cell:
您必须覆盖 mat-cell 的颜色:
.mat-cell {
color: white;
}
or also apply the css class 'highlight' to mat-cell:
或者也将 css 类“highlight”应用于 mat-cell:
<ng-container matColumnDef="bestRider">
<mat-header-cell *matHeaderCellDef mat-sort-header> KOM </mat-header-cell>
<mat-cell *matCellDef="let element; row" [ngClass]="{'highlight': selectedRowIndex == row.id}"> {{element.bestRider}} </mat-cell>
</ng-container>
回答by valerossi46
OK found! I missed "row" in the "matCellDef":
好的找到了!我错过了“matCellDef”中的“row”:
<mat-cell *matCellDef="let row; let element" [ngClass]="{'highlight': selectedRowIndex == row.id}"> {{element.bestRider}} </mat-cell>
Thanks a lot!!!
非常感谢!!!