我想用卡片垂直列出数组中的项目,但是它们之间没有空格。我尝试使用填充,但似乎不起作用。
我应该如何隔开这些卡?
<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;
}
答案 0 :(得分:3)
.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;
...
}
答案 1 :(得分:0)
我花了太多时间来解决这个问题。然后我以为我知道有什么问题,但我的错误是班级名称中只有1个字母。好的,保证金有效。我输入了错误的班级名称。感谢您的回复。