CSS
Flexbox Equal Height Columns for Card Layouts
Easily create columns with dynamic, equal heights in card layouts using CSS Flexbox, ensuring a clean and aligned design regardless of individual content length.
.card-container {
display: flex;
flex-wrap: wrap; /* Allows cards to wrap to the next line */
align-items: stretch; /* Key property: makes all items the same height */
gap: 20px;
padding: 20px;
}
.card {
flex: 1 1 calc(33.33% - 20px); /* Adjusts to 3 columns, accounting for gap */
background-color: #fff;
border: 1px solid #ddd;
border-radius: 8px;
padding: 20px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
display: flex;
flex-direction: column; /* Allows content within card to be flexible */
}
.card-content {
flex-grow: 1; /* Ensures content pushes footer to bottom of card */
}
.card-footer {
margin-top: auto; /* Pushes footer to bottom of card */
padding-top: 10px;
border-top: 1px solid #eee;
text-align: right;
}
How it works: This Flexbox snippet is perfect for creating card-based layouts where all cards in a row need to have the same height, even if their content varies. By setting `display: flex;` and `align-items: stretch;` on the `card-container`, all direct children (`.card`) will stretch to the height of the tallest sibling in their row. `flex: 1 1 calc(33.33% - 20px);` on the cards handles responsive sizing and allows for wrapping, creating a neat, grid-like appearance with uniform height.