Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

.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)?

>Solution :

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>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading