Har*_*lla 6 angular-material angular angular-material-6
我正在尝试减小 mat-select 下拉面板的默认大小,但无法弄清楚如何去做
我试过给 width ,试过在 angular mat-select 中覆盖面板类,但尺寸似乎没有减小
我的模板文件
<div class="col-md-8">
<mat-form-field style="float: right">
<mat-select panelclass="my-panel" placeholder="Select Course"(selectionChange)="selectCourse($event,courses)" disableOptionCentering>
<mat-option *ngFor="let course of courses" [value]="course.courseId">
{{course.courseCode}}
</mat-option>
</mat-select>
</mat-form-field>
</div>
Run Code Online (Sandbox Code Playgroud)
我的 CSS 文件
.my-panel {
background: orange;
height: 300px;
display: flex;
flex-direction: column;
justify-content: space-between;
min-width: 350px !important;
}
Run Code Online (Sandbox Code Playgroud)
您可以通过将以下 css 添加到主styles.css文件来设置 mat-select 的宽度。
.mat-form-field-infix{
width: 80px !important;
}
Run Code Online (Sandbox Code Playgroud)
根据您的要求更改 80px。
您的模板中有一个拼写错误,它需要是panelClass而不是panelclass:
<mat-select panelClass="my-panel" placeholder="Select Course"(selectionChange)="selectCourse($event,courses)" disableOptionCentering>
Run Code Online (Sandbox Code Playgroud)
根据此处的文档,ViewEncapsulation您的组件上的 必须设置None为才能正常工作。panelClass在使用该示例的注释中提到:
// Encapsulation has to be disabled in order for the
// component style to apply to the select panel.
Run Code Online (Sandbox Code Playgroud)
这是一个工作 stackblitz,将您的风格应用于选项。
| 归档时间: |
|
| 查看次数: |
9173 次 |
| 最近记录: |