A.S*_*ice 5 html css angular-material angular
我有一个使用角材料 7 中的垫片的组件。
我想根据打字稿变量的布尔值更改选项卡的背景颜色。
问题是我只能在所有选项卡上应用 CSS
.mat-tab-label {
background-color: red;
}
Run Code Online (Sandbox Code Playgroud)
如何创建一个可以应用于特定选项卡的 CSS 类。
我有一个标准组件。我尝试使用封装:ViewEncapsulation.None 但这只允许我更改上面提到的所有选项卡。
HTML:
<mat-tab-group mat-align-tabs="center" dynamicHeight="true">
<mat-tab label="tab1">
Hello
</mat-tab>
<mat-tab label="tab2">
Hello2
</mat-tab>
</mat-tab-group>
Run Code Online (Sandbox Code Playgroud)
编辑:如果您想更改单个选项卡,您可以使用 aria-label 输入参数。
你必须添加
encapsulation: ViewEncapsulation.None
Run Code Online (Sandbox Code Playgroud)
并使用特定的 css 选择器,如下所示:
HTML:
<mat-tab-group [color]="colorToggle.value" [backgroundColor]="backgroundColorToggle.value">
<mat-tab label="First" [aria-label]=backgroundColorToggle.value> Content 1 </mat-tab>
<mat-tab label="Second"> Content 2 </mat-tab>
<mat-tab label="Third"> Content 3 </mat-tab>
</mat-tab-group>
Run Code Online (Sandbox Code Playgroud)
CSS:
[aria-label=primary] {
background-color: blue;
}
[aria-label=accent] {
background-color: aqua;
}
Run Code Online (Sandbox Code Playgroud)
您可以在这里找到示例
如果您想要所有选项卡:
您有一个专用的 API。
只需使用backgroundColor属性,如下所示:
<mat-tab-group [color]="colorToggle.value" [backgroundColor]="backgroundColorToggle.value">
Run Code Online (Sandbox Code Playgroud)
您可以在这里找到完整的示例
归档时间: |
|
查看次数: |
26589 次 |
最近记录: |