Angular-显示 *ngfor在行和列中
我正在学习使用 Angular,但我对如何在列中显示数据有疑问。
在我的 app.components.ts 中,我有:
<div class="cardComp" *ngFor="let person of people">
<app-card-person [person]="person"></app-card-person>
</div>
// people is an array of objects
在我的 card-person.component.ts 中
<div class="card" style="width: 18rem;">
<!-- <img src="..." class="card-img-top" alt="..."> -->
<div class="card-body">
<h5 class="card-title">{{person?.name}} {{person?.surname}}</h5>
<p class="card-text">{{person?.description}}</p>
<!-- <a href="#" class="btn btn-primary">Go somewhere</a> -->
</div>
</div>
,通过这种方式,我获得了卡片列表,但每行 1 张:
CARD1
CARD2
CARD3
.....
我想要获得的是:
CARD1 CARD2
CARD3 CARD4
..... .....
I'm learning to use Angular and I have a problem with how to show data in columns.
In my app.components.ts I have:
<div class="cardComp" *ngFor="let person of people">
<app-card-person [person]="person"></app-card-person>
</div>
// people is an array of objects
In my card-person.component.ts
<div class="card" style="width: 18rem;">
<!-- <img src="..." class="card-img-top" alt="..."> -->
<div class="card-body">
<h5 class="card-title">{{person?.name}} {{person?.surname}}</h5>
<p class="card-text">{{person?.description}}</p>
<!-- <a href="#" class="btn btn-primary">Go somewhere</a> -->
</div>
</div>
In this way, I obtain a list of cards but they are 1 per row:
CARD1
CARD2
CARD3
.....
What I would to obtain is:
CARD1 CARD2
CARD3 CARD4
..... .....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
解决方案 1:使用 Flexbox
示例解决方案StackBlitz 排名第一
建议阅读这篇 Flexbox 文章。
解决方案 2:使用 Bootstrap
先决条件:导入 Bootstrap CSS 文件。
示例解决方案 2堆栈闪电战
Solution 1: Work with flexbox
Sample Solution 1 on StackBlitz
Recommended to read this Flexbox article.
Solution 2: Work with Bootstrap
Pre-requisites: Import Bootstrap CSS file.
Sample Solution 2 on StackBlitz
CSS 网格
在你的 app.component.scss 中
CSS Grid
In your app.component.scss