我有一个角度材料mat-table,我使用样式的交替行颜色。下面是CSS样式:
.mat-row:nth-child(even){
background-color: #e4f0ec;
}
.mat-row:nth-child(odd){
background-color:#ffffff;
}当我的mat-table没有定义的子行时,这是有效的。当我添加另一个用"expandedDetail“指定的ng-container时,这不再起作用。所有行都是白色的,但展开的子行是彩色的。
我遵循了material.angular.io中的示例
我看到了其他的行样式化的例子,但是他们使用tr标签。在示例和我的代码中,我为每一列使用了ng-container、th和td标记。
如有任何帮助,我们将不胜感激。
我将项目添加到stackblitz
https://stackblitz.com/edit/angular-4bcxtv
下面是我使用的HTML代码
<table mat-table
[dataSource]="dataSource" multiTemplateDataRows
class="mat-elevation-z8">
<ng-container matColumnDef="{{column}}" *ngFor="let column of columnsToDisplay">
<th mat-header-cell *matHeaderCellDef> {{column}} </th>
<td mat-cell *matCellDef="let element"> {{element[column]}} </td>
</ng-container>
<!-- Expanded Content Column - The detail row is made up of this one column that spans across all columns -->
<ng-container matColumnDef="expandedDetail">
<td mat-cell *matCellDef="let element" [attr.colspan]="columnsToDisplay.length">
<div class="example-element-detail"
[@detailExpand]="element == expandedElement ? 'expanded' : 'collapsed'">
<div class="example-element-diagram">
<div class="example-element-position"> {{element.position}} </div>
<div class="example-element-symbol"> {{element.symbol}} </div>
<div class="example-element-name"> {{element.name}} </div>
<div class="example-element-weight"> {{element.weight}} </div>
</div>
<div class="example-element-description">
{{element.description}}
<span class="example-element-description-attribution"> -- Wikipedia </span>
</div>
</div>
</td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="columnsToDisplay"></tr>
<tr mat-row *matRowDef="let element; columns: columnsToDisplay;"
class="example-element-row"
[class.example-expanded-row]="expandedElement === element"
(click)="expandedElement = expandedElement === element ? null : element">
</tr>
<tr mat-row *matRowDef="let row; columns: ['expandedDetail']" class="example-detail-row"></tr>
</table>发布于 2020-07-15 20:35:17
我有问题与垫-选项css,它必须有交替的背景。用下面的方法解决了这个问题:
.mat-option {
&:nth-child(2n+1) {
background-color: #f0efff;
}
&:not(:nth-child(2n+1)) {
background-color: #fff;
}
}请注意,第二个第n个孩子前面有":not“
https://stackoverflow.com/questions/56344338
复制相似问题