css - Angular中具有特定名称的复选框的CSS样式
问题描述
如果我在 Angular 模板中有三个复选框,如下所示:
<mat-checkbox fxFlexFill formControlName="first"> First </mat-checkbox>
<mat-checkbox fxFlexFill formControlName="second"> Second </mat-checkbox>
<mat-checkbox fxFlexFill formControlName="third"> Third </mat-checkbox>
在第一个之前添加空间的正确方法是什么,而不必更改模板?
即我知道我可以在第一个类中添加一个类,但感觉在语义上是错误的(也许我当然错了,但我觉得我应该能够仅使用 css 来做到这一点),所以我想知道它是否是可以做一些类似于输入的事情,即:
// css
mat-checkbox[name="first"] {
margin-top: 10px;
}
解决方案
在您的 css 中,更改name="first"
为formControlName="first"
在您的 html 中没有名为name的属性,而是formControlName。
mat-checkbox[formControlName="first"] {
margin-top: 10px;
background-color: red;
}
<mat-checkbox fxFlexFill formControlName="first"> First </mat-checkbox>
<mat-checkbox fxFlexFill formControlName="second"> Second </mat-checkbox>
<mat-checkbox fxFlexFill formControlName="third"> Third </mat-checkbox>
推荐阅读
- c# - 检查字典是否包含任何具有特定属性的键对象
- xaml - Xamarin 在控件模板中没有填充和扩展
- javascript - 使用 Javascript 中的正则表达式验证 xs:duration
- jquery - jQuery keyup,更改不适用于条形表单
- laravel - Laravel 嵌套依赖注入 - 达到“256”的最大函数嵌套级别
- c++ - HAL 中的硬件特定库
- android - Firebase Analytics 中是否正确收集了归因来源?
- wordpress - 带有 CMB2 和 WPML 媒体的 WordPress:file_list,如何在翻译中获得正确的 id?
- java - android studio 不包括与 Java jUnit 测试一起编写的 Kotlin JUnit 测试
- angular - Safari 浏览器不缓存图像,使用 Angular 构建的站点