[英]adding style to mat-option of mat-autocomplete
<div style="width: 150px">
<form class="example-form">
<mat-form-field class="example-full-width">
<input type="text" placeholder="Assignee" aria-label="Assignee" matInput [formControl]="myControl" [matAutocomplete]="auto">
<mat-autocomplete #auto="matAutocomplete" [displayWith]="displayFn">
<mat-option *ngFor="let option of filteredOptions | async" [value]="option">
{{option.name}}
</mat-option>
</mat-autocomplete>
</mat-form-field>
</form>
</div>
mat-option
的默认行为是使用
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis
我想将长句分成下一行,而不是使用...
。 样式不起作用:(
我还需要覆盖我也尝试使用下面的代码的字体,但它不会覆盖
mat-option {
font-family: "Times New Roman", Times, serif; // does not work
}
请帮忙。
您可以将此添加到您的 CSS:
.mat-option{
word-wrap:break-word !important;
white-space:normal !important;
font-family: "Times New Roman", Times, serif;
}
.mat-option-text{
line-height:initial !important;
}
您的 stlying 不起作用的原因是实际选项显示在<body>
中的叠加层中。 因此选择器component mat-option
不能工作,因为选项没有放在组件中。
要覆盖mat-option
中的任何 styles,您最好解决 class .mat-option
并将其放入全局styles.scss
.mat-option {
font-family: "Times New Roman", Times, serif; // 🦄
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.