我有两列,一列漂浮,另一列漂浮。
内容通常是不同的长度,但内容较少的内容总是需要与更多内容相同。
以下是目前发生的情况:
是否有办法(不固定)以确保它们保持相同的高度?
HTML :
<div class="leftCol">
<div class="singleArrow"></div>
<div class="sectionBlock">
<div class="sectionBlockContentNarrow">
SOME TEXT
</div>
</div>
</div>
<div class="rightCol">
<div class="singleArrow"></div>
<div class="sectionBlock">
<div class="sectionBlockContentNarrow">
SOME TEXT
</div>
</div>
</div>
CSS:
.singleArrow{
margin:0 auto;
width:50px;
height:23px;
background-image:url('../images/downarrow-lrg.png');
background-repeat:no-repeat;
margin-top:20px;
margin-bottom:20px;
}
.leftCol{
float:left;
width:300px;
}
.rightCol{
float:right;
width:300px;
}
.sectionBlock {
position: relative;
overflow: hidden;
box-sizing: border-box;
-webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
-moz-box-sizing: border-box; /* Firefox, other Gecko */
box-sizing: border-box; /* Opera/IE 8+ */
width: 100%;
min-height: 40px;
background-color: rgb(246,246,246);
margin-top: 20px;
background-image: url('../images/bar.png');
background-repeat: repeat-x;
padding: 4px 0 0 10px;
padding-bottom:20px;
}
.sectionBlockContent{
padding: 30px 20px 10px 30px;
}
.sectionBlockContentNarrow{
padding: 30px 10px 10px 10px;
}
答案 0 :(得分:2)
您可以选择2个变种
1。)JS(imho the best)
$(window).load(function() {
//call the equalize height function
equalHeight($("div.left, div.middle, div.right"));
//equalize function
function equalHeight(group) {
tallest = 0;
group.each(function() {
thisHeight = $(this).height();
if(thisHeight > tallest) {
tallest = thisHeight;
}
});
group.height(tallest);
}
});
2。)Bg造型(旧学校)
你需要从你的PSD中削减1 px bg并将bg放到列容器中(repeat-y)
3.)表(旧学校) 的 HTML 强>
<div class="container">
<div class="child">...</div>
<div class="child">...</div>
<div class="child">...</div>
</div>
<强> CSS 强>
.container {
display: table;
}
.child {
display: table-cell;
width: 33.33%;
}
答案 1 :(得分:1)