mat-list-option
标签的aria-selected="true"
属性来选择目标选项,并为其提供相应的CSS属性。mat-list-option[aria-selected="true"] {
background: rgba(0, 139, 139, 0.7);
}
下拉菜单:
mat-list-option
具有mat-option.mat-active
,当选项处于活动状态时会触发,而mat-option.mat-selected
则表示选中的选项。根据需要,添加以下内容到您的CSS中以修改活动或选中的样式。
.mat-option.mat-active {
background: blue !important;
}
.mat-option.mat-selected {
background: red !important;
}
我是一个有用的助手,可以翻译文本。
工作 演示
选择列表:
选择列表具有aria-selected
属性,默认为false
。如果您选择该项目,则会更改为true
。您只需要设置以下CSS即可:
.mat-list-option[aria-selected="true"] {
background: rgba(200, 210, 90, 0.7);
}
正在工作 演示
background: rgba(0, 139, 139, 0.7)
)。如果你决定切换到另一个预构建材料主题或使用自定义主题(如美化你的 Angular Material 应用程序页面所述),这种方法实际上会破坏你的样式和颜色。@import '~@angular/material/theming';
mat-list-option[aria-selected="true"] {
background: mat-color($mat-light-theme-background, hover, 0.12);
}
mat-list-option[aria-selected="true"] {
background: mat-color($mat-dark-theme-background, hover, 0.12);
}
演示: https://stackblitz.com/edit/material-selection-list-5-0-0-selection-color-change-w8beng
如果您想要使用自定义颜色,建议从Material规格中选择一个颜色,这些颜色也在Angular Material Design的scss中公开。
$primaryPalette: mat-palette($mat-green);
mat-list-option[aria-selected="true"] {
background: mat-color($primaryPalette, 500);
}
演示: https://stackblitz.com/edit/material-selection-list-5-0-0-selection-color-change-tt3nyj
该链接是一个演示程序,展示了如何更改Angular Material中列表选择器组件的选定项颜色。[aria-selected]
似乎过于“晦涩难懂”。<mat-list-option #option>
<app-custom-list-option-widget [selected]="option.selected"></app-custom-list-option-widget>
</mat-list-option>
[aria-selected]
.is-selected { color: red; }
<mat-list-option #option>
<span [class.is-selected]="option.selected"> Option text </span>
</mat-list-option>
关于 mat-list-option 属性 CSS 更改,
要更改 onHover CSS:
.mat-list-option:hover {
width: 270px!important;
}
更改OnActive的CSS:
.mat-list-option[aria-selected="true"] {
width: 270px!important;
}
.mat-list-option:active,
.mat-list-text:active{
background-color: none!important;
}