等高布局

等高布局可以使用display:table-cell或者padding与margin对冲两种方法。可以在IE8+使用table-cell,低于IE8使用对冲。

对冲原理
将padding-bottom设置很大,来增加子容器高度,margin-bottom设为padding-bottom相等的负值来恢复子容器高度,
父容器设置overflow:hidden来隐藏子元素。最后,使用内部div相对父容器绝对定位来模拟子容器的底边框。

<div class="container">
     <div class="column left">
           <div class="btLine leftLine"></div>
     </div>
     <div class="column main" style="height: 800px;">
           <div class="btLine mainLine"></div>
     </div>
     <div class="column right">
           <div class="btLine rightLine"></div>
     </div>
</div>
<style>
.container{width:970px;margin:0 auto;position:relative;
display:table-row;overflow:hidden;}
.column{display:table-cell;*margin-bottom:-3000px;*float:left;*padding-bottom:3000px;height:500px;}
.left{width:300px;background:#7bd;border:1px solid green;}
.main{width:500px;background:#e5e5e5;border:1px solid red;}
.right{width:160px;background:#f63;border:1px solid blue;}
.btLine{position:absolute;bottom:0;height:1px;}
.leftLine{background:green;left:0;width:300px;}
.mainLine{background:red;left:300px;width:500px;}
.rightLine{background:blue;right:0;width:160px;}
</style>

 

posted @ 2016-02-29 15:48  全玉  阅读(317)  评论(0编辑  收藏  举报