我正在将一个值传递到 Angular Material 表中以将行颜色设置为黑色,但它一直被我的 css 样式表(将列设置为蓝色)覆盖?我以为内联样式优先,我在这里做错了什么?
我希望这优先(将行值设置为灰色):
<mat-row *matRowDef="let row; columns: displayedColumns;" [ngStyle]="{'background-color': row.color}"></mat-row>
在这个 css 上(将单个列设置为蓝色并使所有其他列保持灰色):
.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%;
}
这是 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>
我的 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%;
}
最佳答案
将下面的 css 添加到您的样式表
.row-color {
background-color: black;
}
那个类到mat-tag
在这样的 html 中 <mat-row [ngClass]=('row-color')></mat-row>
关于html - 如何使内联 HTML 样式覆盖 CSS 样式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57595328/