I am passing a value into an Angular Material Table to set the row color to black, but it keeps getting overridden by my css style sheet (which sets the column to blue)? I thought the inline style took precedence, what am I doing wrong here?
I expected this to take precedence (setting the row value to gray):
<mat-row *matRowDef="let row; columns: displayedColumns;" [ngStyle]="{'background-color': row.color}"></mat-row>
over this css (which sets an individual column to blue and leaves all others gray):
.mat-column-paios, .mat-column-papc, .mat-column-pd, .mat-column-appfamily-pa,
.mat-column-appfamily-pd, .mat-column-eis, .mat-column-appfamily-eis {
background-color: #26428b; /*#3d8299; blue*/
color: white;
flex: 0 0 7%;
}
Here's the HTML:
<mat-table class="lessons-table mat-elevation-z8 overflow-x-auto" [dataSource]="serverLicenseDS" matSort (matSortChange)="sortData($event)">
<ng-container matColumnDef="paios">
<mat-header-cell *matHeaderCellDef>PAIOS</mat-header-cell>
<mat-cell *matCellDef="let e">{{e.paios}}</mat-cell>
</ng-container>
<mat-header-row *matHeaderRowDef="displayedColumns; sticky:true"></mat-header-row>
<mat-row *matRowDef="let row; columns: displayedColumns;" [ngStyle]="{'background-color': row.color}"></mat-row>
</mat-table>
My CSS:
.overflow-x-auto {
overflow-x: auto;
}
.mat-column-select {
overflow: initial;
}
.example-container {
display: flex;
flex-direction: column;
min-width: 300px;
}
.example-header {
min-height: 64px;
padding: 8px 24px 0;
}
.mat-column-sumName {
background-color: black; /*#3d8299; blue*/
color: white;
flex: 0 0 16%;
}
.mat-column-paios, .mat-column-papc, .mat-column-pd, .mat-column-appfamily-pa,
.mat-column-appfamily-pd, .mat-column-eis, .mat-column-appfamily-eis {
background-color: #26428b; /*#3d8299; blue*/
color: white;
flex: 0 0 7%;
}
.mat-column-paplus, .mat-column-pd, .mat-column-dropoff,
.mat-column-appfamily-dropoff, .mat-column-appfamily-paplus {
background-color: #666665; /* #3d993d green*/
color: white;
flex: 0 0 7%;
}
Add the below css to your stylesheet
.row-color {
background-color: black;
}
And that class to mat-tag
in html like this <mat-row [ngClass]=('row-color')></mat-row>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.