【发布时间】:2021-02-22 18:13:01
【问题描述】:
在this Angular 10.2 Material sample 中,左右操作按钮到达card-content 之外:
“创建帐户”按钮的右边缘应与字段的右边缘对齐;同样,“登录”按钮的左边缘应与字段的左边缘对齐。
图像中的绿色是填充区域;橙色是边距;并且,蓝色是行动区域。为什么蓝色和绿色与橙色不对齐?
HTML 是:
<mat-card class="signup-card">
<mat-card-header>
<mat-card-title>The title</mat-card-title>
<mat-card-subtitle>The longer explanatory sub-title.</mat-card-subtitle>
</mat-card-header>
<mat-card-content>
<form [formGroup]="form" (ngSubmit)="onSubmit()">
<div fxLayout="column">
<div fxLayout="row" fxLayoutGap="10px">
<mat-form-field>
<mat-label>First name</mat-label>
<input matInput formControlName="firstName">
</mat-form-field>
<mat-form-field>
<mat-label>Last name</mat-label>
<input matInput formControlName="lastName">
</mat-form-field>
</div>
<mat-form-field>
<mat-label>Email</mat-label>
<input matInput formControlName="email" required>
<mat-error *ngIf="email.errors?.required">Email is required</mat-error>
<mat-error *ngIf="email.errors?.email">Not a valid email</mat-error>
</mat-form-field>
<div fxLayout="row" fxLayoutGap="10px">
<mat-form-field>
<mat-label>Password</mat-label>
<input matInput type="password" formControlName="password" required>
<mat-error *ngIf="password.errors?.required">Password is required</mat-error>
<mat-error *ngIf="password.errors?.minlength">Password is too short</mat-error>
</mat-form-field>
<mat-form-field>
<mat-label>Confirm</mat-label>
<input matInput type="password" formControlName="passwordConfirm" required>
<mat-error *ngIf="passwordConfirm.errors?.required">Confirm password is required</mat-error>
<mat-error *ngIf="passwordConfirm.errors?.mustMatch">Password and confirm must match</mat-error>
</mat-form-field>
</div>
</div>
<mat-card-actions >
<button mat-button routerLink='/signin' routerLinkActive="active" type="button">Sign in</button>
<div fxFlex></div>
<button mat-flat-button routerLink='/signup' routerLinkActive="active" type="submit" color="primary">Create account</button>
</mat-card-actions>
</form>
</mat-card-content>
<mat-card-footer>
The footer containing final parting thoughts...
</mat-card-footer>
</mat-card>
和 CSS:
.mat-card-header {
text-align: center;
justify-content: center;
}
.signup-card {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
似乎我想要的对齐方式应该是默认行为,所以我一定做错了什么......有什么想法吗?
【问题讨论】:
-
一切正常,可以将按钮与我正在使用的内容对齐。
-
感谢@TomaszVizaint——我认为这是一种填充“解决方法”。我想知道为什么绿色填充超出了橙色边距。如果绿色填充 == 橙色边距,则按钮应正确对齐而无需解决方法...
标签: css angular angular-material angular-flex-layout