簡體   English   中英

如何使內聯HTML樣式覆蓋CSS樣式?

[英]How can I make an inline HTML style override a CSS style?

我正在將值傳遞到Angular Material Table中以將行顏色設置為黑色,但是它一直被我的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;
 }

此類要在html中mat-tag類,例如<mat-row [ngClass]=('row-color')></mat-row>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM