Wrapping and growing in CSS
Letting flex items wrap onto new lines, and how they share leftover space.
.chips {
display: flex;
flex-wrap: wrap;
gap: 0.5rem;
align-content: flex-start;
}
.chips > * {
flex: 0 1 auto;
}
.cards {
display: flex;
flex-wrap: wrap;
gap: 1rem;
}
.cards > .card {
flex: 1 1 16rem;
}
How it works
flex-wrap: wrapallows more than one line.flex: 1 1 12remgrows, shrinks, and starts at a sensible basis.align-contentspaces the lines once there are several.
Keywords and builtins used here
cardcardschipsdisplayflexgaprem
The run, in numbers
- Lines
- 20
- Characters to type
- 206
- Tokens
- 64
- Three-star pace
- 80 tpm
At the three-star pace of 80 tokens a minute, this run takes about 48 seconds.
Step 3 of 6 in Flexbox, step 3 of 24 in Flexbox & grid.