并列div自动等高
方法一:css控制
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>完美的DIV三行三列自适应高度布局</title>
<style type="text/css">
body {
margin:0;
padding:0;
font-size:12px;
}
.header {
width:100%;
height:50px;
background:#EEE;
border-bottom:1px solid #000;
}
.colmask {
position:relative;
clear:both;
width:100%;
overflow:hidden;
}
.colright, .colmid, .colleft {
float:left;
width:100%;
position:relative;
}
.col1, .col2, .col3 {
float:left;
position:relative;
overflow:hidden;
}
.threecol {
background:#BBB;
}
.threecol .colmid {
right:20%;
background:#CCC;
}
.threecol .colleft {
right:60%;
background:#DDD;
}
.threecol .col1 {
width:58%;
left:101%;
}
.threecol .col2 {
width:18%;
left:23%;
}
.threecol .col3 {
width:18%;
left:85%;
}
.footer {
clear:both;
width:100%;
height:50px;
background:#EEE;
border-top:1px solid #000;
}
</style>
</head>
<body>
<div class="header"> 这里是头部 </div>
<div class="colmask threecol">
<div class="colmid">
<div class="colleft">
<div class="col1">
<p>这里是中间</p>
<p>这里是中间</p>
<p>这里是中间</p>
<p>这里是中间</p>
<p>这里是中间</p>
<p>这里是中间</p>
<p>这里是中间</p>
</div>
<div class="col2"> 这里是左栏 </div>
<div class="col3">
<p>这里是右栏</p>
<p>这里是右栏</p>
<p>这里是右栏</p>
<p>这里是右栏</p>
</div>
</div>
</div>
</div>
<div class="footer"> 这里是底部 </div>
</body>
</html>
方法二:JS控制
function SetSameHeight(obj1,obj2)
{
var h1 = $(obj1).outerHeight(); //获取对象1的高度
var h2 = $(obj2).outerHeight(); //获取对象2高度
var mh = Math.max( h1, h2); //比较一下
$(obj1).height(mh);
$(obj2).height(mh);
}
在页面用调用:
jQuery(document).ready(function($) {
SetSameHeight(".left",".line");
SetSameHeight(".right_main",".line");//如果有3个div 就加这一行代码,再适应一次.
}
参考博客:http://www.jianshu.com/p/93e61ec8f354