更改网格样式的顺序(砌体)

时间:2018-12-05 14:09:08

标签: css grid masonry

我有一个网格样式:

<div class="masonry">
    <div class="item">10</div>
    <div class="item">9</div>
    <div class="item">8</div>
    <div class="item">7</div>
    <div class="item">6</div>
    <div class="item">5</div>
    <div class="item">4</div>
    <div class="item">3</div>
    <div class="item">2</div>
    <div class="item">1</div>
</div>

css:

.masonry {
    column-count: 5;
    column-gap: 1em;
    margin-top: 20px;
}
.item {
    display: inline-block;
    margin: 0 0 1em;
    width: 100%;
}

结果在此图中(按列列出订单): Current image 但我想按行订购商品。首先,填写第一行,然后填写第二行,依此类推my favorite state

1 个答案:

答案 0 :(得分:0)

我使用flexbox看到了下面的代码,我相信这就是您想要的

.masonry {
    margin-top: 20px;
    display: flex;
     flex-direction: row-reverse; 
     align-items: flex-end;
     flex-wrap: wrap;
}
.item {
    margin: 0 0 1em;
    width: 20%;
}
<div class="masonry">
    <div class="item">10</div>
    <div class="item">9</div>
    <div class="item">8</div>
    <div class="item">7</div>
    <div class="item">6</div>
    <div class="item">5</div>
    <div class="item">4</div>
    <div class="item">3</div>
    <div class="item">2</div>
    <div class="item">1</div>
</div>