我有bootstrap4,我试图让某个列的高度等于另一个列的高度。这是我的密码:
<div class="container" style="overflow:hidden">
<div class="row" style="overflow:hidden">
<div class="col-md-8" id="firstColumn">
<div class="row">
<div class="col-md-6">
</div>
<div class="col-md-6">
</div>
</div>
<div class="row">
<div class="col-md">
</div>
</div>
</div>
<div class="col-md-4" id="secondColumn" style="overflow:auto">
</div>
</div>
</div>
我的第二列
的高度高于firstColVIII
,但我希望它具有与firstColVIII
相同的高度,同时也可滚动。
我想提到的是,我的列处于一个模式中,当用户单击按钮时,它将从我的数据库加载数据并填充该模式。因此,在页面加载时,如果我将它们的高度设置为相等,则不会起作用。
我建议最好使用resizejquery事件查看两个div的高度,并将较短div的高度设置为较高div的高度。
像这样的东西:
$(window).resize(function() {
firstHeight = $("#firstColumn").height();
secondHeight = $("#secondColumn").height();
if (firstHeight > secondHeight) {
$("#secondColumn").height(firstHeight);
} else {
$("#firstColumn").height(secondHeight);
}
}
很可能您也希望在页面打开时运行此功能,这样您就可以使内容成为一个命名函数,您可以在ready和resize触发器中调用该函数。
使用Flexbox!
.wrapper {
display: flex;
flex-direction: row;
border: 5px solid yellow;
}
.colA {
background-color: #EAE;
flex: 1 0 auto;
line-height: 2em;
}
.colB {
background-color: #AEE;
flex: 1 0 auto;
max-height: 70px;
overflow-y: scroll;
line-height: 2em;
}
<div class="wrapper">
<div class="colA">
One Line
</div>
<div class="colB">
More<br/>
than<br/>
one<br/>
line!
</div>
</div>