【发布时间】:2019-06-24 10:46:18
【问题描述】:
我有一个带有子 div 的 flex div (.parent)(你猜对了,.child),它包含更多的行。我的问题是我似乎无法让每个 div .card 的边框具有相同的高度而不破坏我的“网格”。当我尝试为.child 等指定特定高度时,高度看起来很糟糕,因为不是每一行都有相同长度的内容。我见过这样的例子,但不知道如何用 flex 解决它,以便多行具有相同的高度(没有每个“单元格”的高度相同并且产生尽可能多的混乱。
.parent {
display: flex;
flex-grow: 1;
flex-wrap: wrap;
margin: 0 auto;
max-width: 100%;
width: 100%;
}
.child {
height: 100%;
margin-top: 20px;
margin: 1%;
display: inline-flex;
}
.a-title {
font-size: 1.3em;
font-weight: 700;
width: 100%;
}
.child .card {
border-radius: 3px;
border: 1px solid;
font-size: .8em;
padding: 10px;
display: inline-block;
overflow: hidden;
/* height: 600px; */
}
<div class="parent">
<div class="child">
<div class="card">
<img src="https://i.imgur.com/D1p6UX3.jpg" width="240" height="240"><br>
<p class="a-title">
Title
</p>
<p>
Some example text that I'm too lazy to ipsum right now.
</p>
<p>
Some example text that I'm too lazy to ipsum right now.
</p>
<p>
Some example text that I'm too lazy to ipsum right now.
</p>
<p>
Some example text that I'm too lazy to ipsum right now.
</p>
<p>
<a href="#">Some fake link</a>
</p>
</div>
</div>
<div class="child">
<div class="card">
<img src="https://i.imgur.com/D1p6UX3.jpg" width="240" height="240"><br>
<p class="a-title">
Title
</p>
<p>
Some example text that I'm too lazy to ipsum right now.
</p>
<p>
Some example text that I'm too lazy to ipsum right now.
</p>
<p>
<a href="#">Some fake link</a>
</p>
</div>
</div>
<div class="child">
<div class="card">
<img src="https://i.imgur.com/D1p6UX3.jpg" width="240" height="240"><br>
<p class="a-title">
Title
</p>
<p>
Some example text that I'm too lazy to ipsum right now.
</p>
<p>
Some example text that I'm too lazy to ipsum right now.
</p>
<p>
Some example text that I'm too lazy to ipsum right now.
</p>
<p>
Some example text that I'm too lazy to ipsum right now.
</p>
<p>
Some example text that I'm too lazy to ipsum right now.
</p>
<p>
Some example text that I'm too lazy to ipsum right now.
</p>
<p>
<a href="#">Some fake link</a>
</p>
</div>
</div>
<div class="child">
<div class="card">
<img src="https://i.imgur.com/D1p6UX3.jpg" width="240" height="240"><br>
<p class="a-title">
Title
</p>
<p>
Some example text that I'm too lazy to ipsum right now.
</p>
<p>
Some example text that I'm too lazy to ipsum right now.
</p>
<p>
Some example text that I'm too lazy to ipsum right now.
</p>
<p>
<a href="#">Some fake link</a>
</p>
</div>
</div>
<div class="child">
<div class="card">
<img src="https://i.imgur.com/D1p6UX3.jpg" width="240" height="240"><br>
<p class="a-title">
Title
</p>
<p>
Some example text that I'm too lazy to ipsum right now.
</p>
<p>
Some example text that I'm too lazy to ipsum right now.
</p>
<p>
<a href="#">Some fake link</a>
</p>
</div>
</div>
<div class="child">
<div class="card">
<img src="https://i.imgur.com/D1p6UX3.jpg" width="240" height="240"><br>
<p class="a-title">
Title
</p>
<p>
Some example text that I'm too lazy to ipsum right now.
</p>
<p>
Some example text that I'm too lazy to ipsum right now.
</p>
<p>
<a href="#">Some fake link</a>
</p>
</div>
</div>
<div class="child">
<div class="card">
<img src="https://i.imgur.com/D1p6UX3.jpg" width="240" height="240"><br>
<p class="a-title">
Title
</p>
<p>
Some example text that I'm too lazy to ipsum right now.
</p>
<p>
Some example text that I'm too lazy to ipsum right now.
</p>
<p>
Some example text that I'm too lazy to ipsum right now.
</p>
<p>
Some example text that I'm too lazy to ipsum right now.
</p>
<p>
<a href="#">Some fake link</a>
</p>
</div>
</div>
</div>
试图避免这里发生的事情(当前代码示例):https://jsfiddle.net/4gy7fzw1/
没有设置高度的代码示例:https://jsfiddle.net/t2yzfkm9/
【问题讨论】: