gpt4 book ai didi

css - 使用 Bootstrap 3,列是否可以换行并保持相同的高度?

转载 作者:行者123 更新时间:2023-11-28 11:27:18 24 4
gpt4 key购买 nike

使用 Bootstrap 3,是否可以让列换行并与行中最大的列高度相同?

我知道可以强制同一行中的列高度相同 using flexbox , 但当列换行时是否可以具有相同的列高?

.row.display-flex {
display: flex;
flex-wrap: wrap;
}
.row.display-flex > [class*='col-'] {
display: flex;
flex-direction: column;
}

div[class*='col-'] {
background-color: #eaeaea;
border: 1px solid;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row display-flex">
<div class="col-md-6">
ShouldBeSameHeightAsMultiLineColumn
</div>

<div class="col-md-6">
Multi line content that will wrap to the next line. Multi line content that will wrap to the next line. Multi line content that will wrap to the next line.
</div>

<div class="col-md-6">
ShouldBeSameHeightAsMultiLineColumn
</div>

<div class="col-md-6">
ShouldBeSameHeightAsMultiLineColumn
</div>
</div>

最佳答案

在这种情况下,我将使用 jQuery。

$(document).ready(function(){
var biggestHeight = 0;
var flexColumns = $('.display-flex > div');
flexColumns.each(function(){
if($(this).height() > biggestHeight){
biggestHeight = $(this).height();
}
});
flexColumns.height(biggestHeight);
});
.row.display-flex {
display: flex;
flex-wrap: wrap;
}
.row.display-flex > [class*='col-'] {
display: flex;
flex-direction: column;
}

div[class*='col-'] {
background-color: #eaeaea;
border: 1px solid;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row display-flex">
<div class="col-md-6">
ShouldBeSameHeightAsMultiLineColumn
</div>

<div class="col-md-6">
Multi line content that will wrap to the next line. Multi line content that will wrap to the next line. Multi line content that will wrap to the next line.
</div>

<div class="col-md-6">
ShouldBeSameHeightAsMultiLineColumn
</div>

<div class="col-md-6">
ShouldBeSameHeightAsMultiLineColumn
</div>
</div>

关于css - 使用 Bootstrap 3,列是否可以换行并保持相同的高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44557384/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com