css - 使用 mat-form-field 更改特定字段中的背景颜色
问题描述
所以,我有一个现有的 mat-form-field,我想更改特定字段的背景颜色。我已经在 css 中尝试过这段代码,但它改变了我表单中所有字段的背景颜色:
::ng-deep .mat-form-field-appearance-outline .mat-form-field-outline {
background-color: lightgray !important;
border-radius: 5px;
}
这是我的 mat-form-field 的代码:
<mat-label>Filing Time</mat-label><br />
<mat-form-field appearance="outline" class="width-1">
<input
matInput
readonly
formControlName="filingTime"
[ngModel]="filingDate | date: 'HH:mm'"
/>
</mat-form-field>
解决方案
更新了工作示例
您可以通过提供 id 或类来更改将任何 CSS 应用于特定元素。
这是使用它的代码Class
::ng-deep .mat-form-field-appearance-outline.specific-border .mat-form-field-outline {
background-color: lightgray !important;
border-radius: 5px;
}
<mat-label>Filing Time</mat-label><br />
<mat-form-field appearance="outline" class="width-1 specific-border">
<input
matInput
readonly
formControlName="filingTime"
[ngModel]="filingDate | date: 'HH:mm'"
/>
</mat-form-field>
这是使用它的代码Id
::ng-deep .mat-form-field-appearance-outline#specific-border .mat-form-field-outline {
background-color: lightgray !important;
border-radius: 5px;
}
<mat-label>Filing Time</mat-label><br />
<mat-form-field appearance="outline" id="specific-border" class="width-1">
<input
matInput
readonly
formControlName="filingTime"
[ngModel]="filingDate | date: 'HH:mm'"
/>
</mat-form-field>
推荐阅读
- html - 响应式图像和文本
- android - 内部应用更新:使用内部应用共享进行测试时,clientVersionStalenessDays() 返回 null
- php - PHP insert into 不插入也不报错,但在使用远程 SQL 时会 insert into
- html - 如何在布尔玛水平居中瓷砖?
- java - 从树集中获取值时如何获取 IllegalArgumentException?
- javascript - WebRTC 视频聊天结束通话按钮
- highcharts - Highstock + angular material + flex-layout 问题
- rest - 在 REST API 中对对象的操作进行建模的最合适方法是什么?
- asp.net - 了解 asp.net 核心端点路由的结构
- mysql - Sequelize(mysql)中的小写列值-Node JS