【发布时间】:2019-10-18 02:23:24
【问题描述】:
我正在尝试在 ngFor 循环中使用 flexbox 来获取列中的数据。 Flexbox wrap 属性打开以在较小的屏幕上显示数据。但即使在更大的屏幕上,数据也会成行显示。我的代码是
<div class="main" *ngFor="let hero of heros">
<div class="child"><mat-checkbox color='primary'>{{hero.name}}</mat-checkbox></div>
</div>
css 是
.main {
width: 90%;
list-style-type: none;
margin: 0.5em;
padding: 0.5em;
display: flex;
flex-wrap: wrap;
}
.child {
width: 400px;
}
英雄对象是
heros = [
{id: 1, name: 'Superman'},
{id: 2, name: 'Batman'},
{id: 5, name: 'BatGirl'},
{id: 3, name: 'Robin'},
{id: 4, name: 'Flash'}
];
【问题讨论】:
-
.child{display:inline-block} -
试试
flex-wrap: nowrap;?
标签: css angular flexbox angular7 ngfor