我对基于 Angular Material 的应用程序中的 flex 布局行为有疑问。我想要一个简单的“卡片网格”布局,排成 3 张卡片(最大的屏幕),2 张中等大小的卡片和 1 张小屏幕的卡片。问题是当我在最大屏幕的最后一行只有一张卡时,因为最后一张卡的宽度是屏幕宽度的 100%。如何避免这个问题?
这是我当前的代码。
<div class="page-wrapper">
<div fxLayout="row wrap" fxLayoutGap="16px" class="align" *ngIf="!loading">
<mat-card fxFlex.lg="calc(33% - 16px)" fxFlex.lt-lg="calc(50% - 16px)" fxFlex.xs="calc(100% - 16px)"
*ngFor="let post of posts">
<mat-card-header>
<mat-card-title>{{ getCleanString(post.title.rendered) }}</mat-card-title>
<mat-card-subtitle>{{ post.date_gmt | date }}</mat-card-subtitle>
</mat-card-header>
<img matCardImage [src]="post['_embedded']['wp:featuredmedia'][0]['media_details'].sizes['medium'].source_url"
class="card-image">
<mat-card-content [innerHTML]="post.excerpt.rendered"></mat-card-content>
<mat-card-actions align="start">
<a mat-button color="primary" [href]="post.link">Czytaj więcej</a>
</mat-card-actions>
</mat-card>
</div>
</div>
编辑:卡之间的差距没有问题。问题是最后一张卡片具有整个布局的 100% 宽度(而不是其他卡片的 1/3)。