【发布时间】:2021-02-10 09:18:53
【问题描述】:
我正在制作一个有角度的模板驱动表单,我希望能够更改输入标签的颜色,例如选择无效时,选择。
以下是从表单中选择输入的示例:
<div class="select__wrapper">
<label for="car-year">
<span>Year of manufacture</span>
</label>
<select
[(ngModel)]="vehicle.year"
name="year"
id="car-year"
required
class="form-control">
<option *ngFor="let year of years" [ngValue]="year.value">
{{ year.display }}
</option>
</select>
</div>
When a select is invalid, the class ng-invalid is added to the element.
很容易改变选择样式:
.select__wrapper {
.ng-invalid {
border-color: red;
color: red;
}
}
我还想在选择无效时更改标签颜色。我在stackoverflow上找到了以下内容:
How to select parent pseudo-class from within child using scss
这使用了兄弟组合,但是我必须重新排序我的元素并用位置来修改它们。我想知道是否有更好的方法是使用 SCSS 和/或 angular 来实现?
谢谢
【问题讨论】:
-
理想情况下,我只想用一些 SASS 来做这件事,避免任何打字稿