gpt4 book ai didi

html - Angular *ngFor 生成表 4 个单元格宽

转载 作者:太空宇宙 更新时间:2023-11-04 05:51:05 25 4
gpt4 key购买 nike

我在组件文件中有一个数组,它将根据数据库查询动态更新。我需要这个数组来填充这样一个表的内容:

对于包含 7 个元素的数组:

---------------------------------------------
| array[0] | array[1] | array[2] | array[3] |
---------------------------------------------
| array[4] | array[5] | array[6] |
----------------------------------

目前我有这个方法:

HTML:

<table>
<ng-container *ngFor="let employer of businessAdmins">
<tr>
<div class="card shadow m-2" style="height:25vh;width:18.75vh;border-radius:5%;overflow:hidden;">
<div class="ml-1"><div style="font-weight:bold">Name: </div>{{employer.data().first_name + " " + employer.data().last_name}}</div>
</div>
</tr>
</ng-container>
</table>

这在生成单元格列表时效果很好,但是我不知道如何水平填充它们,直到有 4 个水平单元格,然后移动到下一行。

最佳答案

使用 CSS flex box 非常简单。试试这段代码 -

HTML

<div class="table">
<ng-container *ngFor="let employer of businessAdmins">
<div class="card shadow">
<div style="font-weight:bold">
Name: {{employer.data().first_name + " " + employer.data().last_name}}
</div>
</div>
</ng-container>
</div>

CSS

.table {
display: flex;
flex-wrap: wrap;
width: 100%;

.card {
flex: 1 0 25%;
}
}

结果-

enter image description here

关于html - Angular *ngFor 生成表 4 个单元格宽,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58268764/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com