div高度随浏览器变化

代码
<!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>div高度随浏览器变化,兼容all</title>
<script type="text/javascript">
    
//兼容手动改变浏览器大小和F11全屏
    window.onload=window.onresize=function(){
        
var h=document.documentElement.clientHeight-50;
        document.getElementById(
'con').style.height=h+'px';
    }
</script>
</head>

<body style="margin:0; padding:0">
<div id="con" style="400px; background-color:#F00; border:1px solid #f00; margin:20px auto"></div>
</body>
</html>
原文地址:https://www.cnblogs.com/bennman/p/1938263.html