日期:2014-05-17 浏览次数:20820 次
<!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">
<style>
body{margin:0px}
</style>
<div   style="background:red;overflow:hidden;"   id="layer1">
    <div   id= "header"   style= "WIDTH:100%;height:22px; "> header </div>
    <div   id= "context"   style= "border-style:solid;   border-width:1px;   width:   100px;   height:   100%; "> context </div>
</div>
<script type="text/javascript">
<!--
function getSize() {
    var xScroll, yScroll;
    if (window.innerHeight && window.scrollMaxY) {
        xScroll = document.body.scrollWidth;
        yScroll = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight){      // all but Explorer Mac
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    } else {      // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }
    var windowWidth, windowHeight;
    if (self.innerHeight) {      // all except Explorer
        windowWidth = self.innerWidth;
        windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) {      // Explorer 6 Strict Mode
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    } else if (document.body) {      // other Explorers
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }
    // for small pages with total height less then height of the viewport
    if(yScroll < windowHeight){
        pageHeight = windowHeight;
        y = pageHeight;
    } else {
        pageHeight = yScroll;
        y = pageHeight;
    }
    if(xScroll < windowWidth){
        pageWidth = windowWidth;
    } else {
        pageWidth = xScroll;
    }
    arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
    return arrayPageSize;
}
//这段代码用来获取目标页的参数,包括页面宽、高,屏幕宽、高,分别装入数组arrayPageSize[0]、[1]、[2]、[3]
window.onload = function(){
    document.getElementById('layer1').style.height = getSize()[3] + 'px'    
    document.getElementById('context').style.height = getSize()[3] - 24 + 'px'
}    
window.onresize = function(){
    document.getElementById('layer1').style.height = getSize()[3] + 'px'    
    document.getElementById('context').style.height = getSize()[3] - 24 + 'px'
}
//-->
</script>
------解决方案--------------------
纯CSS不可能,因为有一个事件需要响应!可以把代码都集合在css样式里面,不过资源占有会大一些!
<div   style= "border-style:solid;   border-width:1px;   width:   100%;   height:  100%; "   id= "layer1"> 
<div   i