问题描述
我只想在一个组件中更改p-table
的标题单元格的背景颜色,怎么办?
我尝试了<ng-template pTemplate="caption" class="myStyle">
和.myStyle{ background: rgb(9,169,121) !important; }
在my.component.scss
但它不起作用。
救救我!谢谢!
编辑:终于可以了!我看到了@Antikhippe的答案,但我不得不添加
:host :: ng-deep { #myTable {
.p-datatable-thead { 背景:红色;
} .p-datatable .p-datatable-thead> tr> th { 背景:继承; } }
解决方法
pTemplate="caption"
仅适合表标题的一部分,您必须使用p-datatable-header
类:
尝试一下:
:host ::ng-deep {
#myTable {
.p-datatable-header {
background-color: red;
}
}
}
我用p-datatable-header
包围了#myTable
类,以将此CSS仅应用于ID为myTable
的表:
<p-table id="myTable" [value]="products">
请参见StackBlitz