angular-material - Angular Material 中的样式 mat-radio-button
问题描述
我刚刚开始在我的 Angular 应用程序中使用 Angular Material 主题。
我使用了一些单选按钮,但想设置它们的样式,使它们比平时小。我可以设置文本标签的样式,但我正在努力设置实际按钮本身(圆圈)的样式。
所以现在,我有
<mat-radio-group class="smallRadio">
<mat-radio-button value="1">Option 1</mat-radio-button>
<mat-radio-button value="2">Option 2</mat-radio-button>
</mat-radio-group>
我该怎么做呢?
解决方案
尝试这个,
默认半径是20px
我们将其设置为10px
这里
:host ::ng-deep .mat-radio-container{
height: 10px;
width: 10px;
}
:host ::ng-deep .mat-radio-outer-circle{
height: 10px;
width: 10px;
}
:host ::ng-deep .mat-radio-inner-circle{
height: 10px;
width: 10px;
}
:host ::ng-deep .mat-radio-button .mat-radio-ripple{
height: 20px; /*double of your required circle radius*/
width: 20px; /*double of your required circle radius*/
left: calc(50% - 10px); /*'10px'-same as your required circle radius*/
top: calc(50% - 10px); /*'10px'-same as your required circle radius*/
}
不使用::ng-deep
关闭使用自定义收音机的组件的封装。
你可以这样做
import {Component,ViewEncapsulation} from '@angular/core';
@Component({
selector: 'example',
templateUrl: 'example.component.html',
styleUrls: ['example.component.css'],
encapsulation : ViewEncapsulation.None,
})
export class ExampleComponent {}
将您想要样式的组件包装在自定义类中。因此它不会影响任何其他无线电组件。在上面的问题中,它已经被smallRadio
类包裹了
.smallRadio .mat-radio-container{
height: 10px;
width: 10px;
}
.smallRadio .mat-radio-outer-circle{
height: 10px;
width: 10px;
}
.smallRadio .mat-radio-inner-circle{
height: 10px;
width: 10px;
}
.smallRadio .mat-radio-button .mat-radio-ripple{
height: 20px;
width: 20px;
left: calc(50% - 10px);
top: calc(50% - 10px);
}
您可以在全局样式表中添加这些 css,而无需关闭视图封装。但更优雅的方法是上面的一种
推荐阅读
- django - LiveServerTestCase - 内部服务器错误联系管理员
- python - 安装 NLopt - Python - Windows
- json - fromMap 正在从 json 响应中分配空值
- r - R中的混合效应逻辑回归模型
- java - Android 应用程序如何在主进程中多次初始化?
- javascript - Facebook 分享中的图片链接过期?
- php - 如何获得每个参与者的自定义问题的答案?(雄辩)
- angular - Angular+ 组件继承 - 在子节点中使用订阅
- java - 带有 API 23 android 的特定错误 NavigationView
- oop - 如何发现 Perl 6 类型的所有角色?