[英]Blocks side-by-side with the same height
OK, what I need is fairly simple, though it's one of those things that I've never managed to get my head around when using CSS. 好的,我所需要的是相当简单的,尽管这是我在使用CSS时从未设法了解的事情之一。 So, here I am... 所以,我在这里
I'm using a custom template, built around Twitter Bootstrap. 我正在使用围绕Twitter Bootstrap构建的自定义模板。
This template features a section (declared as span6 row
), containing small blocks (declared as span3
). 该模板具有一个节(声明为span6 row
),其中包含小块(声明为span3
)。 In the end, the sub-blocks form rows (2 blocks per row). 最后,子块形成行(每行2个块)。
Here's a visual example : 这是一个视觉示例:
The result is ok, though I'd still need one thing : 其结果是好的,但我仍然需要一两件事:
HOW do I make sure that 2 adjacent blocks have the exact same height? 如何确定两个相邻的块具有完全相同的高度? (eg The 1st block - "Some title here" - and the 2nd block - "Awesome work" - white rectangles being of the exact same height, no matter what the contents are... (much like the 2 last blocks)). (例如,第一个块- “ Some title here” -和第二个块- “ Awesome work” -白色矩形的高度完全相同,无论内容如何……(与最后两个块一样)。
Any ideas? 有任何想法吗?
PS PS
<!-- ------------------------------------------
Bootstrap 2 : Markup
Credit : http://www.2scopedesign.co.uk/responsive-equal-height-columns-in-bootstrap/
------------------------------------------- -->
<div class="row">
<div class="span6">
<div class="content-box">
Content here
</div>
</div>
<div class="span6">
<div class="content-box">
Content here
</div>
</div>
</div>
<!-- ------------------------------------------
jQuery part
------------------------------------------- -->
<script>
//equal height plugin
$.fn.max = function(selector) {
return Math.max.apply(null, this.map(function(index, el) {return selector.apply(el);}).get() );
}
$(window).load(function(){
equalHeight();
});
$(window).resize(function(){
$('.content-box').css('height', '');
equalHeight();
});
function equalHeight(){
if ( $( window ).width() > 768 ) {
$('.content-box').height(function () {
var maxHeight = $(this).closest('.row').find('.content-box').max( function () {
return $(this).height();
});
return maxHeight;
});
}
else {
$('.content-box').css('height', '');
}
}
</script>
Try the following: 请尝试以下操作:
1) Assigning parent div with "display:table" and child div's with "display:table-cell" like: 1)为父div分配“ display:table”,为子div分配“ display:table-cell”,例如:
CSS:
.parent-div{
border: 1px solid grey;
display: table;
float: none;
}
.child div{
border: 1px solid grey;
min-height: 100%;
height: 100%;
display: table-cell;
float: none;
}
HTML:
<div class="span6 parent-div">
<div class="row">
<div class="span3 child-div">
......
</div>
<div class="span3 child-div">
......
</div>
</div>
2) You can also use "EqualHeights jQuery Plugin": 2)您也可以使用“ EqualHeights jQuery插件”:
Include it your head by adding 通过添加来包括你的头
<script language="javascript" type="text/javascript" src="jquery.equalheights.js"></script>
And call the function on your .parent-div as: 并在.parent-div上将函数调用为:
$('.parent-div').equalHeights();
For detailed usage and limitations, whether it is suitable for your website first read this and proceed. 有关详细的使用和限制,无论是适合你的网站第一次读到这 ,然后继续。
Set a min-width. 设置最小宽度。 So in your css have: #whatevertheboxitscalled { min-width:100px; }
因此,在您的CSS中有: #whatevertheboxitscalled { min-width:100px; }
#whatevertheboxitscalled { min-width:100px; }
Obviously it doesn't have to be 100px, but whatever size fits best. #whatevertheboxitscalled { min-width:100px; }
显然,这并不一定是100像素,但无论大小最适合。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.