首页 > 解决方案 > 垂直分离 Angular Material 卡片

问题描述

我想用卡片垂直列出数组中的项目,但它们之间没有空格。我尝试使用填充,但它似乎不起作用。

卡片图片

我怎样才能让这些卡片间隔?

<ng-container *ngIf="titles?.length; else noTitle">
    <mat-card class="asd cardPardding" *ngFor="let title of titles">
      <p>
      {{title}}
      </p>
    </mat-card>
  </ng-container>

  <ng-template #noTitle>
    <mat-card class="asd cardPardding">
      <p>
      No title !
      </p>
  </mat-card>
  </ng-template>

这是CSS

.asd {
  width: 80%;
  margin: 0 auto; /* Added */
}

.inputasd {
  width: 100%;
}

.cardPadding {
  padding: 100px;
  margin-bottom: 50px;
}

标签: cssangularangular-materialngfor

解决方案


.component.html

<ng-container *ngIf="titles?.length; else noTitle">
    <mat-card class="my-class-name asd cardPardding" *ngFor="let title of titles">
        <p>
            {{title}}
        </p>
    </mat-card>
</ng-container>

<ng-template #noTitle>
    <mat-card class="asd cardPardding">
        <p>
            No title !
        </p>
    </mat-card>
</ng-template>

.css/.scss 文件

.my-class-name{
    margin-bottom: 10px;
    ... 
}

推荐阅读