div如何高度自适应延伸到浏览器底部

方法1:

<html>
<head>
    <title></title>
    <script language="javascript" type="text/javascript">
        window.onload = function() {
            var div = document.getElementById("csdn");
            div.style.position = "absolute";
            div.style.top = "0";
            div.style.height = document.documentElement.clientHeight;
        }
  </script>

</head>
<body>
 <div id="csdn" style="background-color: #FF0000; width: 200px;">
  1234567890-=<br />
  1234567890-=<br />
 </div>   
</body>
</html>

2. 方法2

方法1在有些场合还是无法解决问题,

var height = document.documentElement.scrollHeight;
                          if (height > 30) {
                              height = height - 30;
                              $("body").css('height', height);
                          }
                      }

这里使用了 document.documentElement.scrollHeight

猜你喜欢

转载自www.cnblogs.com/digdeep/p/12585112.html