![](/img/trans.png)
[英]How to style mat-option text to get the text outside mat-select panel on hovering over every mat-option text
[英]Adding mat-divider to mat-select/mat-option
是否有可能有一个垫分隔器(一条分隔两个垫选项的水平线)?
我努力了:
<mat-form-field>
<mat-label>Cars</mat-label>
<select matNativeControl required>
<option value="volvo">Volvo</option>
<mat-divider></mat-divider>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
</mat-form-field>
我现在有一个不好的解决方法是:
<mat-option>--------------------------</mat-option>
然而这并不理想。
I am not sure how exactly you want the divider to appear, but a pure CSS approach would be to overwrite the .mat-option
class on your main styles.css
, make use of the :after
pseudo element , and add a value to the border-bottom
CSS 属性。
.mat-option:after {
content: '';
width: 100%;
border-bottom: solid 2px black;
position: absolute;
left: 0;
z-index: 1;
top: calc(3em - 2px);
}
我在这里创建了一个演示。
是的,可以将 mat-divider 添加到 mat-select/mat-option
<mat-form-field>
<mat-label> Cars </mat-label>
<mat-select>
<mat-option value="volvo"> Volvo </mat-option>
<mat-divider></mat-divider>
<mat-option value="saab"> Saab </mat-option>
<mat-divider></mat-divider>
<mat-option value="mercedes"> Mercedes </mat-option>
<mat-divider></mat-divider>
<mat-option value="audi"> Audi </mat-option>
</mat-select>
希望对你有帮助
您可以使用mat-divider
本身来实现这一点,只需将ng-container
添加到包装mat-option
和mat-divider
即可。 然后使用last
ngFor
局部变量有条件地从最后一个mat-option
中删除mat-divider
。
<mat-select>
<ng-container *ngFor="let food of foods; let last = last">
<mat-option [value]="food.value">
{{food.viewValue}}
</mat-option>
<mat-divider *ngIf="!last"></mat-divider>
</ng-container>
</mat-select>
这是StackBlitz上的一个工作示例。
Angular 材料 Select 文档为您提供帮助,您可以使用 panelClass 指令,如他们显示的示例:
<mat-form-field>
<mat-label>Panel color</mat-label>
<mat-select [formControl]="panelColor"
panelClass="example-panel-{{panelColor.value}}">//panelColor.value if you want to handle some class dynamically
<mat-option value="red">Red</mat-option>
<mat-option value="green">Green</mat-option>
<mat-option value="blue">Blue</mat-option>
</mat-select>
</mat-form-field>
这些是他们处理的 css 类
.example-panel-red.mat-select-panel {
background: rgba(255, 0, 0, 0.5);
}
.example-panel-green.mat-select-panel {
background: rgba(0, 255, 0, 0.5);
}
.example-panel-blue.mat-select-panel {
background: rgba(0, 0, 255, 0.5);
}
因此,您可以在 class 中应用 gojun css 属性
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.