【问题标题】:Css to align the material design radio buttonsCss 对齐材料设计单选按钮
【发布时间】:2019-09-12 04:37:13
【问题描述】:

我正在使用 mat-radio-buttons。 我预期的 UI 应该是这样的,

使用以下代码,

     <mat-radio-group name="employeeType" formControlName="employeeType" fxLayout="row">
                   <mat-radio-button *ngFor="let type of employeeTypes" (change)="showFieldByEmployeeType($event)"
                       [value]="type.name">
                       {{ type.name}}</mat-radio-button>
               </mat-radio-group>

但我明白了,

是否有任何有用的 CSS 让它看起来像预期的那样?

【问题讨论】:

    标签: css radio-button material-design angular8


    【解决方案1】:

    模板

     <mat-radio-group class="radio-parent" name="employeeType" 
    formControlName="employeeType" 
    fxLayout="row">
               <mat-radio-button class="radio-item" *ngFor="let type of employeeTypes" 
    (change)="showFieldByEmployeeType($event)"
                   [value]="type.name">
                   {{ type.name}}</mat-radio-button>
           </mat-radio-group>
    

    CSS

    .radio-parent{
        display: flex;
        justify-content: space-between;
        align-items: center;
        flex-wrap: wrap;
    }
    .radio-item{
     flex: 1 0 21%;
      margin: 5px;
     }
    

    它不会生成完全相同的结构,您必须使用值来获得所需的结构。

    【讨论】:

    • 谢谢@pratik。我刚刚将 flex:1 0 21% 更改为 flex:1 0 19% 以获得预期的效果。
    猜你喜欢
    • 2023-04-05
    • 1970-01-01
    • 2021-09-14
    • 2015-09-15
    • 2016-06-28
    • 2015-01-04
    • 2017-05-01
    • 2022-12-20
    • 1970-01-01
    相关资源
    最近更新 更多