方法1:
<!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=gb2312" />
<title>div布局,如何使左侧div高度与右侧的div高度自适应相同</title>
<style type="text/css">
.center{ width:900px; margin:0px auto;overflow:hidden;}
.left{ width:250px;background:#CCCCCC; float:left;height:100px; margin-bottom:-10000px; padding-bottom:10000px; overflow:hidden; }
.right{width:650px; background:#dedede; float:left; margin-bottom:-10000px; padding-bottom:10000px;overflow:hidden; }
</style>
</head>
<body>
<div class="center">
<div class="left">left </div>
<div class="right">right<p>right<p>right<p>right<p>right<p></div>
</div>
</body>
</html>
方法2:
<!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=gb2312" />
<title>div布局,如何使左侧div高度与右侧的div高度自适应相同</title>
<style type="text/css">
#center{ width:900px; margin:0px auto;}
#left{width:250px;height:200px;background:#CCCCCC;float:left; }
#right{width:650px;background:#dedede;float:left;}
</style>
</head>
<body>
<div id="center">
<div id="left">left </div>
<div id="right">right<p>right<p>right<p>right<p>right<p> right<p>right<p>
</div>
</div>
<script language="javascript">
document.getElementById("left").style.height=document.getElementById("right").scrollHeight+"px";
</script>
</body>
</html>
已有 0 条评论