css - 无法更改下拉 mat-form-field CSS - Angular 材质
问题描述
当我尝试使用角材料的 mat-form-field 在两件事上更改下拉的 CSS 时,我遇到了一个问题:
我的 CSS 不会更改属性
<option> and <optgroup>
。无法更改
:hover
CSS<option>
下拉菜单的位置“剪切”当前选定的选项。
我的下拉式 atm(默认角度材料):
html:
<mat-form-field class="drop-down" appearance="fill">
<select matNativeControl [(ngModel)]="currentActiveModeValue" (change)="onModeChange($event)">
<optgroup *ngFor="let mainModes of activeModArry; let i = index" label="{{ mainModes.name }}">
<option *ngFor="let subModes of mainModes.childModes" [value]="subModes.id">
{{ subModes.name }}
</option>
</optgroup>
</select>
</mat-form-field>
我想做的风格:
真的需要一些帮助,如果有人以前遇到过这个问题:)
解决方案
在您的代码示例中,要使悬停起作用,您必须使用材料元素,然后在 css 中使用::ng-deep
,还要验证它在组件的 .ts 中的 .ts 中没有封装集@Component
。
在 html 中,它看起来像这样:
<mat-form-field class="drop-down" appearance="fill">
<mat-select matNativeControl [(ngModel)]="currentActiveModeValue" (change)="onModeChange($event)">
<mat-optgroup *ngFor="let mainModes of activeModArry; let i = index" label="{{ mainModes.name }}">
<mat-option *ngFor="let subModes of mainModes.childModes" [value]="subModes.id">
{{ subModes.name }}
</mat-option>
</mat-optgroup>
</mat-select>
</mat-form-field>
而css会是这样的
::ng-deep mat-option:hover {
...
}
推荐阅读
- java - 从对象中删除重复项并合并到数组中
- flutter - 如何将 GridView 导航到 Flutter 中的另一个页面?
- azure - 从 Azure 函数调用 Azure 活动目录密码重置策略
- c++ - 检测二维数组中具有共同属性的连续对象
- google-sheets - 如果页面名称更改,如何在将不断更新的列中获取电子表格文件的所有页面名称?
- html - 将 HTML 注入 Mailgun 模板变量
- python - Python Selenium 无法找到按钮类名
- python-3.x - 当尝试从 Visual Studio Code 运行 import pandas 时,它抛出了 ImportError,但在 Anaconda(Jupyter Notebook)中工作正常
- vue.js - 如何在 vuetify 复选框中设置不确定状态?
- c++ - 为什么在 C++ 中我们使用 SetCursorPos(10,20); 而不是 BOOL SetCursorPos(10,20); 为什么会抛出编译错误?