【发布时间】:2023-03-07 14:54:01
【问题描述】:
基本上,我正在寻找一种使一组 4 个 div 具有相同高度的方法。 div 的内容是动态的,因此有时扩展的内容会迫使其中一个 div 垂直扩展并使集合中每个 div 的高度不一致。最好用这个例子来解释:
HTML
<div class="answers">
<div class="a-b">
<a href="#" class="answer" id="A">Michael Jackson</a>
<a href="#" class="answer" id="B">Stevie Wonder</a>
</div>
<div class="c-d">
<a href="#" class="answer" id="C">Lionel Richie</a>
<a href="#" class="answer" id="D">This answer could contain more text</a>
</div>
</div>
CSS
.answers {
margin-top: 35px;
}
.a-b {
width: 50%;
float: left;
}
.c-d {
width: 50%;
float: right;
}
.answer {
display: inline-block;
border-radius: 32px;
text-decoration: none;
background-color: #1797FF;
color: white;
padding: 10px 33px;
font-size: 22px;
width: 75%;
margin-bottom: 20px;
}
如何保持 2x2 布局并强制每个 div 具有相同的高度(由具有最多文本的 div 决定)?
【问题讨论】: