如何使左右两个自适应高度的div等高

让向左浮动的div的高度随着向右浮动的div的高度变化而变化,左右两个div都是自适应高度的

  可以用js实现左右两个自适应高度的div等高。

  具体代码如下:

<script type="text/javascript">
<!--
window.onload=window.onresize=function(){
if(document.getElementById("mm2").clientHeight<document.getElementById("mm1").clientHeight){
document.getElementById("mm2").style.height=document.getElementById("mm1").offsetHeight+"px";
}
else{
document.getElementById("mm1").style.height=document.getElementById("mm2").offsetHeight+"px";
}
}
-->
</script>
温馨提示:内容为网友见解,仅供参考
第1个回答  2012-03-28
通常我为了省麻烦会用table布局,2个td是高度自适应并且等高的

如果非要用div布局的话,那就要用到js脚本了,我直接发个链接给你好了,你参考一下
http://www.lanrentuku.com/js/table-21.html

http://www.lanrentuku.com/js/website-153.html本回答被提问者采纳
第2个回答  2012-03-29
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
<style type="text/css">
body,div {margin:0;padding:0}
#MainBody {width:1000px;height:100%;overflow:hidden;margin:0 auto}
.a {width:500px;height:100%;float:left;overflow:hidden;background-color:#000}
.b {width:500px;height:100%;float:right;overflow:hidden;background-color:#F00}
</style>
</head>

<body>
<div id="MainBody">
<div class="a"></div>
<div class="b">
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
</div>
</div>
<script type="text/javascript">
$(function(){
var tarHight = $(".b").height();
$(".a").height(tarHight);
})
</script>
</body>
</html>

记得引入JQ库文件
相似回答