<div id="d1"> <input type="text" value="hello" /> </div> <div id="d2" style="height:200px;background-color:blue;"></div> <div id="d3" style="height:100%;background-color:red"></div>
宽和高都用百分比
xuejun405,你看下d3的style我用了100%的
加一个:html,body{height:100%;}
加了不行
<div id="d1"> <input type="text" value="hello" /> </div> <div id="d2" style="height:200px;background-color:blue;"></div> <div id="d3" style="height:100%;background-color:red"></div>
js更正版,窗口更改大小后也可以重置d3大小
<body style="height:100px;margin:0px"> <div id="d1"> <input type="text" value="hello" /> </div> <div id="d2" style="height:200px;background-color:blue;"></div> <div id="d3" style="background-color:red"></div> </body><script> function resetD3() { var css1 = document.compatMode == 'CSS1Compat'; var h = document[css1 ? 'documentElement' : 'body'].clientHeight; var d1 = document.getElementById('d1'), d2 = document.getElementById('d2'), d3 = document.getElementById('d3') d3.style.height = h - d1.offsetHeight - d2.offsetHeight + 'px'; } window.onload = window.onresize = resetD3;</script>