通过改变
.card
元素到
display: flex;
flex-direction: column;
并加入
margin-top: auto;
到描述。这将导致描述元素被推到卡的底部。因为卡片是垂直拉伸的,所以对齐在水平轴上工作。如果你改变了,情况就不一样了
align-items
上
.card-container
成为别人
stretch
.
.card {
display: flex;
flex-direction: column;
text-align: center;
flex: 50%;
padding: 15px 0;
}
.card-img img {
width: 60px;
padding: 15px;
}
.card-title {
font-weight: 700;
text-transform: uppercase;
margin-bottom: 10px;
font-size: 1.2rem;
}
.card-desc {
font-weight: 400;
margin: 0;
margin-top: auto;
line-height: 1rem;
}
.card-container {
background: rgba(255, 0, 0, 0.432);
display: flex;
flex-wrap: wrap;
justify-content: center;
flex: 100%;
}
@media screen and (min-width: 500px) {
.card {
flex: 1;
}
.card-img img {
width: 50px;
}
.card-title {
font-weight: 700;
text-transform: uppercase;
margin-bottom: 10px;
font-size: 1.2rem;
}
.card-desc {
font-weight: 400;
line-height: 1rem;
}
.card-container {
background: rgba(255, 0, 0, 0.432);
display: flex;
flex-wrap: wrap;
justify-content: center;
flex: 100%;
}
}
<div class="card-container">
<div class="card">
<div class="card-img"><img src="https://via.placeholder.com/500x500"></div>
<h4 class="card-title">Just a title</h4>
<p class="card-desc">A simple description</p>
</div>
<div class="card">
<div class="card-img"><img src="https://via.placeholder.com/500x500"></div>
<h4 class="card-title">Just a title</h4>
<p class="card-desc">A simple description</p>
</div>
<div class="card">
<div class="card-img"><img src="https://via.placeholder.com/500x500"></div>
<h4 class="card-title">A veeeeery very very very large title</h4>
<p class="card-desc">omg, that description have broken :(</p>
</div>
<div class="card">
<div class="card-img"><img src="https://via.placeholder.com/500x500"></div>
<h4 class="card-title">Just a title</h4>
<p class="card-desc">A simple description</p>
</div>
<div class="card">
<div class="card-img"><img src="https://via.placeholder.com/500x500"></div>
<h4 class="card-title">Just a title</h4>
<p class="card-desc">A simple description</p>
</div>
</div>