[英]CSS/Bootstrap: How to stretch containers within cols full-height?
I'm using the simple Bootstrap-Grid: one row, two col-md-6
-columns. 我使用的是简单的Bootstrap-Grid:一行,两个
col-md-6
列。 Within each column I've a container class="box"
, which should use a height of 100%
. 在每一列中,我都有一个容器
class="box"
,其height of 100%
应height of 100%
。
I tried different ways, eg simulating a table and table-cols, but chose the .row-eq-height
-class, recommended by Bootstrap. 我尝试了不同的方法,例如模拟表和表
.row-eq-height
,但是选择了Bootstrap建议的.row-eq-height
-class。
Whats the common way to force the box
within col-md-6
to stretch to full-height? 强制
col-md-6
的box
拉伸到全高的常用方法是什么?
HTML: HTML:
<div class="row row-eq-height">
<div class="col-md-6">
<div class="box" style="background: red">
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
</div>
</div>
<div class="col-md-6">
<div class="box" style="background: green">
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
</div>
</div>
</div>
CSS: CSS:
.row-eq-height {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
}
.col-md-6 {
background: yellow; /* to show the left space */
}
.box {
height: 100%;
}
Live: 生活:
http://jsfiddle.net/cmbe4h1h/ http://jsfiddle.net/cmbe4h1h/
Edit: I would like to avoid wrapping the HTML with additional containers (like in many position: relative/absolute
-tutorials). 编辑:我想避免用其他容器包装HTML(例如在许多
position: relative/absolute
教程)。
Thanks in advance! 提前致谢!
I didn't find a proper CSS solution for my case and switched to 我没有为我的情况找到合适的CSS解决方案,并切换到
JS ( jQuery ) : JS( jQuery ) :
$('.sameHeightWrapper').each(function() {
var highestContainer = 0;
$('.sameHeightContainer', this).each(function() {
if($(this).height() > highestContainer) {
highestContainer = $(this).height();
}
});
$('.sameHeightContainer', this).height(highestContainer);
});
HTML : HTML :
<div class="sameHeightWrapper">
<div class="sameHeightContainer c1">
Container 1<br/>
...
</div>
<div class="sameHeightContainer c2">
Container 2<br/>
...
</div>
<div class="sameHeightContainer c3">
Container 3<br/>
Container 3<br/>
...
</div>
</div>
Try it: jsfiddle.net 尝试一下: jsfiddle.net
CSS solution . CSS解决方案 。 removed the padding on the
col-md-6
class. 删除了
col-md-6
类的填充。 also moved your bg inline style to the outer container, not the box
class. 也将您的bg内联样式移到了外部容器,而不是
box
类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.