html - 如何使内联 HTML 样式覆盖 CSS 样式?

标签 html css angular

我正在将一个值传递到 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/

相关文章:

javascript - 如何使用 Javascript/jQuery 更改背景图片?

css - 如何突出显示 md-card 或更改 Angular 2 中 med-card 的背景颜色

javascript - Angular 6 : not set properties of class after calling HTTP-request

javascript - 使用 jquery 检查表中的行是否具有 css 类

html - 通过适当的文本换行垂直排列输入字段

javascript - 表格中的响应式 c3 图表

html - 如何使用 CSS 将这两个无序列表并排放置?

javascript - 将数据从两个组件传输到服务( Angular 2)

Angular 7 react 形式 "No value accessor for form control with unspecified name attribute"

javascript - Angular JS : HTML in $scope throws jshint error?