先设置div+css 基本布局:
<div id="mm">
<div id="mm1">左边</div>
<div id="mm2">右边</div>
</div>
js 实现 div 自适应高度
代码如下:
<script type="text/javascript">
<!--
window.onload=window.onresize=funct {
if document.getElementByIdx_x "mm2" .clientHeight<document.getElementByIdx_x "mm1" .clientHeight {
document.getElementByIdx_x "mm2" .style.height=document.getElementByIdx_x "mm1" .offsetHeight+"px"
}
else{
document.getElementByIdx_x "mm1" .style.height=document.getElementByIdx_x "mm2" .offsetHeight+"px"
}
}
-->
</script>
很简单,利用table的自适应的属性即可。最外层定义一个dispaly:table就好,如果要宽度到左右两边,高度自适应的话,可以这样设置,代码如下:
.ctn {width:100%display:table}<!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>
<style type="text/css">
html, body { height: 100%margin: 0padding: 0}
.wrap { width: 100%height: 100%}
.fixed { float: leftwidth: 200pxheight: 100% background: #000margin-left: -100%}
.main { float: leftwidth: 100%height: 100%}
.main-inner { margin-left: 200px background: #f00height: 100%}
</style>
</head>
<body>
<div class="wrap">
<div class="main">
<div class="main-inner">
test
</div>
</div>
<div class="fixed">a</div>
</div>
</body>
</html>
-------
html和body的高度设置为100%, 这样才能让div#wrap的高度生效.
若要将左侧高度固定,将.fixed的height设置为固定值就行了.