【发布时间】:2019-06-01 02:38:14
【问题描述】:
<div fxLayout="row wrap" fxLayout.xs="column" fxLayoutAlign="space-around center" fxLayoutGap="10px">
<mat-card *ngFor="let o of cards">
<mat-card-header>
<div mat-card-avatar class="example-header-image"></div>
<mat-card-title>{{o.title}}</mat-card-title>
<mat-card-subtitle>{{o.subtitle}}</mat-card-subtitle>
</mat-card-header>
<img mat-card-image [src]="o.url" alt="Photo of {{o.title}}">
<mat-card-content>
<p>
{{o.content}}
</p>
</mat-card-content>
</mat-card>
</div>
其中cards 在组件上定义为:
// const url = 'https://material.angular.io/assets/img/examples/shiba2.jpg';
cards: {title: string, subtitle: string, content: string, url: string}[] = [
{ title: 'Title', subtitle: 'Subtitle', content: 'Content here', url },
{ title: 'Title', subtitle: 'Subtitle', content: 'Content here', url },
{ title: 'Title', subtitle: 'Subtitle', content: 'Content here', url },
{ title: 'Title', subtitle: 'Subtitle', content: 'Content here', url },
{ title: 'Title', subtitle: 'Subtitle', content: 'Content here', url },
{ title: 'Title', subtitle: 'Subtitle', content: 'Content here', url },
{ title: 'Title', subtitle: 'Subtitle', content: 'Content here', url },
{ title: 'Title', subtitle: 'Subtitle', content: 'Content here', url },
{ title: 'Title', subtitle: 'Subtitle', content: 'Content here', url },
{ title: 'Title', subtitle: 'Subtitle', content: 'Content here', url },
{ title: 'Title', subtitle: 'Subtitle', content: 'Content here', url },
{ title: 'Title', subtitle: 'Subtitle', content: 'Content here', url },
{ title: 'Title', subtitle: 'Subtitle', content: 'Content here', url },
{ title: 'Title', subtitle: 'Subtitle', content: 'Content here', url },
{ title: 'Title', subtitle: 'Subtitle', content: 'Content here', url },
{ title: 'Title', subtitle: 'Subtitle', content: 'Content here', url },
{ title: 'Title', subtitle: 'Subtitle', content: 'Content here', url },
{ title: 'Title', subtitle: 'Subtitle', content: 'Content here', url },
];
但是我没有尝试过在行上给出间距。我试过fxFlexOffset、fxLayoutAlign 和各种gd 前缀。
【问题讨论】:
-
直截了当的解决方案怎么样:mat-card{ margin:5em }
-
当然,我可以使用
mat-card {margin-bottom: 5em;},而且我总是可以处理第 n 个类并为列做同样的事情。但是我不应该为此使用@angular/flex-layout吗? - 这似乎是一个常见的用例。
标签: angular flexbox angular-material angular-flex-layout