html - 如何以 3 列显示列表

标签 html css

我有一个使用 *ngFor 垂直显示的列表。 我需要在 3 列上显示此列表;

我尝试使用d-flex flex-wrap但这并没有解决问题。我还为 div 设置了固定宽度,但这给了我一个滚动列表。

这是我的代码

<div class="d-flex flex-wrap container">
    <li *ngFor="let item of list">
       <input type="checkbox" [(ngModel)]="item.value" />
       <label> {{item.name}} </label>
    </li>
</div>

我也尝试在 div 上使用 ngFor,认为 flex-wrap 只适用于 div,但它给了我相同的结果

<div class="d-flex flex-wrap container">
    <div *ngFor="let item of list">
       <input type="checkbox" [(ngModel)]="item.value" />
       <label> {{item.name}} </label>
    </div>
</div>

enter image description here

最佳答案

使用 row 将 DOM 和 col-3 包装到包装内的每个 div

如下:

<div class="container row">
    <div *ngFor="let item of list" class="col-3">
       <input type="checkbox" [(ngModel)]="item.value" />
       <label> {{item.name}} </label>
    </div>
</div>

See example here

关于html - 如何以 3 列显示列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63774570/

相关文章:

javascript - IE10/Safari 无法隐藏 iFrame 中的对象/Flash

html - 在窗口调整大小时移动 div

html - 网格 960 调整大小后占据整个宽度

javascript - 自动拖放文件上传

javascript - 如何使用 "position:fixed"将 img 固定到弹出式 div?

html - 什么决定了 Firefox 中的滚动条是否有颜色?

javascript - 在 DOM 中查找子值的父值

html - 如何在 CSS 中为 calc() 值设置最小值

html - 餐厅网站应该使用 PDF 还是 HTML 作为菜单以获得最佳 SEO?

html - 添加页脚,当内容不多时,该页脚会粘在页面底部