【发布时间】:2019-06-02 05:38:15
【问题描述】:
我正在尝试水平对齐列表中不同类型的 Angular Material 表单控件中的单选/复选框。该列表是 mat-list-option、mat-checkbox 和 mat-radio-button 的组合。我需要标签左对齐,而复选框/单选按钮右对齐。
我试过使用 fxLayouts“行”和“空格”,但没有运气。我也尝试过篡改 CSS,但似乎无法正确处理。我创建了一个 StackBlitz:https://stackblitz.com/edit/material-6-kj87kz
<mat-selection-list>
<ng-container *ngFor="let text of texts">
<mat-list-option [checkboxPosition]="'after'">
{{ text }}
</mat-list-option>
<div style="padding: 0 16px">
<mat-checkbox *ngIf="isCheckbox" fxLayout="row" fxLayoutAlign="space-between center">
{{ text }}
</mat-checkbox>
<mat-radio-group *ngIf="isRadioGroup" fxLayout="column" fxLayoutAlign="space-between center">
<mat-radio-button *ngFor="let subText of subTexts" fxLayout="row" [labelPosition]="'before'">
{{ subText }}
</mat-radio-button>
</mat-radio-group>
</div>
</ng-container>
</mat-selection-list>
请注意,我已经从代码中删除了绑定、条件和操作,以保持简单。这是我目前得到的:
如您所见,我很难让控件对齐。有谁知道如何做到这一点的好方法?
【问题讨论】:
-
你能提供一个能重现你的问题的 stackblitz 吗?
-
@PierreDuc stackblitz.com/edit/material-6-kj87kz
-
有人知道如何完成这个吗?
标签: html css angular user-interface angular-material