[英]Make all div children have the same height
My website has 3 boxes but also, a very definitive margin between all 3. As such, I don't think I can use CSS display:table
to fix this issue so How to make div boxes with floats have the same height with dynamic content doesn't help :( 我的网站有3个盒子,但所有3个盒子之间都有很大的余量。因此,我认为我无法使用CSS
display:table
来解决此问题,因此, 如何使带有浮动内容的div盒子具有与动态内容相同的高度没有帮助:(
.wrapper div { float:left; } .box1 { background:blue; margin-right:10%; } .box2 { background:red; margin:0 10%; } .box3 { background:green; margin-left:10%; }
<div class="wrapper"> <div class="box1">asdf </div> <div class="box2">asdf sadf<br /> saf safs<br /> fsdf saf</div> <div class="box3"> asdf <br />asdf <br />asdf <br />asdf <br />asdf <br /> asdf <br />asdf <br />sfsa dfsdaf sdf sdf </div> </div>
In my head, the wrapper has a height (which is the height of the highest child), and as such I would have hoped adding height:inherit
would have worked in .box1, .box2 or .box3 but not 在我的脑海中,包装器有一个高度(这是最高的孩子的高度),因此我希望增加
height:inherit
将在.box1,.box2或.box3中起作用,但不能
display:flex
features are not fully supported yet so I don't want to use it. display:flex
功能尚不完全受支持,因此我不想使用它。
How do I make all 3 the same height without using a fixed height. 如何在不使用固定高度的情况下使所有3个高度相同。
Actually you can use CSS display:table to fix this. 实际上,您可以使用CSS display:table来解决此问题。 Below are the CSS, HTML and Fiddle
以下是CSS,HTML和Fiddle
.wrapper {display:table;} .box1 {background:pink;display: table-cell;} .box2 {background:red;display: table-cell;} .box3 {background:green;display: table-cell;}
<div class="wrapper"> <div class="box1">asdf </div> <div class="box2">asdf sadf<br /> saf safs<br /> fsdf saf</div> <div class="box3"> asdf <br />asdf <br />asdf <br />asdf <br />asdf <br />asdf <br />asdf <br />sfsa dfsdaf sdf sdf </div> </div> </div> </div>
If you are open to use a jQuery library, use this - http://brm.io/jquery-match-height/ 如果您愿意使用jQuery库,请使用它-http://brm.io/jquery-match-height/
Then its as simple as assigning a class and then do this: 然后,就像分配一个类一样简单,然后执行此操作:
$(".equal-heights").matchHeight();
You can use equalizer by zurb foundation. 您可以通过zurb基础使用均衡器 。
HTML HTML
<div class="wrapper" data-equalizer>
<div class="box1" data-equalizer-watch>asdf </div>
<div class="box2" data-equalizer-watch>asdf sadf<br /> saf safs<br /> fsdf saf</div>
<div class="box3" data-equalizer-watch>asdf <br />asdf <br />asdf <br />asdf <br />asdf <br />asdf <br />asdf <br />sfsa dfsdaf sdf sdf </div>
</div>
Add .js: 添加.js:
<script src="js/vendor/jquery.js"></script>
<script src="js/foundation/foundation.js"></script>
<script src="js/foundation/foundation.equalizer.js"></script>
Start equalizer: 启动均衡器:
<script>
$(document).foundation();
</script>
I know you don't want to use flex but just in case. 我知道您不想使用flex,以防万一。
You can try something like this JSFiddle : 您可以尝试这样的JSFiddle :
.wrapper {
display: flex;
}
.wrapper div {
display: flex;
align-items: center;
}
.box1 {
background:blue;
margin-right:10%;
}
.box2 {
background:red;
margin:0 10%;
}
.box3 {
background:green;
margin-left:10%;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.