Flexbox: 4 items per row

前端 未结 9 1168
南笙
南笙 2020-11-22 13:01

I\'m using a flex box to display 8 items that will dynamically resize with my page. How do I force it to split the items into two rows? (4 per row)?

Here is a releva

9条回答
  •  情深已故
    2020-11-22 13:31

    Add a width to the .child elements. I personally would use percentages on the margin-left if you want to have it always 4 per row.

    DEMO

    .child {
        display: inline-block;
        background: blue;
        margin: 10px 0 0 2%;
        flex-grow: 1;
        height: 100px;
        width: calc(100% * (1/4) - 10px - 1px);
    }
    

提交回复
热议问题