I'm trying to achieve equal height columns/cards on some flex-items.
When the title or the card product title element does not span more than 1 line
The design acts as it should
Working Example:
BUT When the title breaks onto a second line the design breaks.
Broken Example
<div class="card">
<div class="title">iPhone 14 White Pearl</div>
<div class="img"> </div>
<div class="desc">Lorem ipsum dolor sit amet consectetur adipisicing elit.</div>
<button>Add to Cart</button>
</div>
<div class="card">
<div class="title">iPhone 14 White Pearl</div>
<div class="img"> </div>
<div class="desc">Lorem ipsum dolor sit amet consectetur adipisicing elit.</div>
<button>Add to Cart</button>
</div>
<div class="card">
<div class="title">iPhone 14 White Pearl (Unlocked - GSM)</div>
<div class="img"> </div>
<div class="desc">Lorem ipsum dolor sit amet consectetur adipisicing elit.</div>
<button>Add to Cart</button>
</div>
<div class="card">
<div class="title">iPhone 14 White Pearl</div>
<div class="img"> </div>
<div class="desc">Lorem ipsum dolor sit amet consectetur adipisicing elit.</div>
<button>Add to Cart</button>
</div>
<div class="card">
<div class="title">iPhone 14 White Pearl</div>
<div class="img"> </div>
<div class="desc">Lorem ipsum dolor sit amet consectetur adipisicing elit. Lorem ipsum dolor sit amet consectetur Lorem ipsum dolor sit amet consectetur </div>
<button>Add to Cart</button>
</div>
<div class="card">
<div class="title">iPhone 14 White Pearl</div>
<div class="img"> </div>
<div class="desc">Lorem ipsum dolor sit amet consectetur adipisicing elit.</div>
<button>Add to Cart</button>
</div>
THE CSS
.container {
display: grid;
margin: 30px auto 10px;
max-width: 1024px;
grid-template-columns: 1fr 1fr 1fr 1fr;
gap: 30px;
}
.card {
width: 200px;
display: flex;
flex-direction: column;
flex-basis: 1;
align-items: stretch;
}
.card .title {
padding: 0 0 10px;
font-family: 'Avenir Next', sans-serif;
font-size: 15px;
/* flex: 1 0 auto; */
}
.card .img {
width: 100%;
height: 120px;
background-color: purple;
}
.card .desc {
justify-self: flex-start;
flex: 2 0 auto;
padding: 10px 0;
}
.card button {
padding: 10px;
outline: none;
border: none;
color: white;
background-color: teal;
}
@media screen and (max-width: 768px) {
.container {
grid-template-columns: 1fr 1fr;
}
}
It seems like having two flex-grow; properties inside of a flex-item column container doesn't yield the behavior I thought it would.
Edit: As I'm writing this I realized that the heights are infact equal height. What is not happening is even distribution and flush alignment amongst the other sibiling containers when the Card title breaks onto a second line - which is what i'm truly after. Any and all help is appreciated