I'm creating a card-style layout, in which individual cards stack vertically. At higher screen widths, more and more columns of cards are used - using as little vertical space as possible.
I'm using a flex-flow: column wrap
layout to do this. However, what I find is that the container is required to have a height
or max-height
in order to encourage the cards to wrap. Given that the number of cards and their individual size may change, I can't tell what this height will optimally be without cutting off items or having excessive space below.
Can anyone tell me if this is possible, or if I'm doing something wrong?
Snippet attached.
.card-container {
display: flex;
flex-flow: column wrap;
align-items: stretch;
}
.card {
flex: 0 0 auto;
width: 15rem;
margin: 0.5rem;
background-color: #f4f4f4;
/* max-height: ??? */
}
<div class="card-container">
<div class="card" style="height: 20em"></div>
<div class="card" style="height: 17em"></div>
<div class="card" style="height: 5em"></div>
<div class="card" style="height: 10em"></div>
<div class="card" style="height: 21em"></div>
<div class="card" style="height: 10em"></div>
<div class="card" style="height: 17em"></div>
<div class="card" style="height: 8em"></div>
<div class="card" style="height: 20em"></div>
<div class="card" style="height: 16em"></div>
<div class="card" style="height: 19em"></div>
<div class="card" style="height: 10em"></div>
<div class="card" style="height: 5em"></div>
</div>