造型垫选择角度材料
如何设置mat-select的面板组件的样式.从我得到的文档,我需要提供panelClass所以我这样做:
<mat-form-field> <mat-select placeholder="Search for" [(ngModel)]="searchClassVal" panelClass="my-select-panel-class" (change)="onSearchClassSelect($event)"> <mat-option *ngFor="let class of searchClasses" [value]="class.value">{{class.name}}</mat-option> </mat-select> </mat-form-field> 我在开发人员工具中检查过这个类是否附加到DOM中的面板并附加了它.所以我将自定义scss类附加到此元素.现在,当我提供CSS时,它只是不起作用.我的scss例如如下所示: .my-select-panel-class { width:20px; max-width:20px; background-color: red; font-size: 10px; } 面板的宽度始终等于select元素的宽度.有时在选项中你有太长的字符串,我想让它更广泛.有什么方法可以做到这一点.我的组件中的风格即使不起作用也不起作用.有人知道为什么这么奇怪吗? 我在用着:
Angular Material使用mat-select-content作为选择列表内容的类名.对于它的造型,我建议四种选择.
1.使用::ng-deep:
CSS: ::ng-deep .mat-select-content{ width:2000px; background-color: red; font-size: 10px; } DEMO 2.使用ViewEncapsulation
没有值是您需要打破封装并从组件中设置材质样式. Typscript: import {ViewEncapsulation } from '@angular/core'; .... @Component({ .... encapsulation: ViewEncapsulation.None }) CSS .mat-select-content{ width:2000px; background-color: red; font-size: 10px; } DEMO 3.在style.css中设置类样式 这次你必须’强制’样式!重要的是. style.css文件 .mat-select-content{ width:2000px !important; background-color: red !important; font-size: 10px !important; } DEMO 4.使用内联样式 <mat-option style="width:2000px; background-color: red; font-size: 10px;" ...> DEMO (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |