Phil S.
Phil S.

Reputation: 3

CSS Flexbox: grow first flex items instead of last ones

I have a flex-boxes layout that grows the boxes in the final "row", like here:

Screenshot

The CSS:

.container {
    display: flex;
    flex-flow: row wrap;
    align-items: stretch;
}

.item {
    flex-grow: 1;
    flex-shrink: 0;
    display: inline-block;

    position: relative; width: 14em; height: 14em; min-width: 14em;
}

The question: can one indicate in such a row flow to preferably grow the "first" flex-items rather than the "last" ones (via CSS not JS)?

Upvotes: 0

Views: 553

Answers (1)

Mr. Stash
Mr. Stash

Reputation: 3160

You can add flex-wrap: wrap-reverse; in the container class, and in your html add the elements in reverse order

.container {
    display: flex;
    flex-flow: row wrap;
    align-items: stretch;
    flex-wrap: wrap-reverse;
}
<div class="container">
    <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>

Upvotes: 1

Related Questions