垂直对齐 mat-checkbox 和 mat-form-field | 角材料| 角

abh*_*yak 5 html css angular-material angular

我正在尝试并排实现文本字段和复选框。像这样的东西。 在此输入图像描述

但是,问题是<mat-form-field>并且<mat-checkbox>不是垂直对齐。我如何通过将它们垂直对齐来继续前进?

这是代码:

<mat-card>
    <mat-card-title>
        Family Information
    </mat-card-title>
    <form [formGroup]="familyInfo">
        <div fxLayout="row" fxLayoutAlign="flex-start" fxLayoutGap="40px">
            <mat-form-field fxFlex="10%">
                <mat-label>Contact Name</mat-label>
                <input matInput>
            </mat-form-field>
            <mat-form-field fxFlex="10%">
                <mat-label>Relation Type </mat-label>
                <mat-select>
                    <mat-option *ngFor="let relationType of relationTypes" [value]="relationType" color="accent">
                        {{relationType}}
                    </mat-option>
                </mat-select>
            </mat-form-field>
            <mat-form-field fxFlex="10%">
                <mat-label>Gender </mat-label>
                <mat-select>
                    <mat-option *ngFor="let gender of genders" [value]="gender" color="accent">
                        {{gender}}
                    </mat-option>
                </mat-select>
            </mat-form-field>
            <mat-form-field fxFlex="10%">
                <mat-label>Date Of Birth</mat-label>
                <input matInput [matDatepicker]="dateOfBirth" formControlName="dateOfBirth">
                <mat-datepicker-toggle matSuffix [for]="dateOfBirth"></mat-datepicker-toggle>
                <mat-datepicker #dateOfBirth></mat-datepicker>
            </mat-form-field>

            <mat-checkbox formControlName="isDependent">Is Dependent</mat-checkbox>

            <div fxFlex="100%"></div>
            <mat-card-actions>
                <button mat-raised-button color="primary" type="submit" class="align-right-button">
                    Save
                </button>
            </mat-card-actions>
        </div>
Run Code Online (Sandbox Code Playgroud)

我尝试使用<mat-form-field>,但根据角度材料文档。<mat-checkbox>不能成为<mat-form-field>

小智 2

您必须手动放置复选框。没有其他方法可以对元素进行排列。类似于 mat-checkbox 的东西align-self: center

请注意,mat-form-field有一些自定义填充/边距。因此,为了获得完美的装配,您需要检查元素并在顶部添加几个 px。根据字体大小的不同而有所不同。

希望这会有所帮助。祝你好运!