Make DIV fill remainder of page vertically?

后端 未结 6 1317
时光取名叫无心
时光取名叫无心 2020-12-04 17:34

I have a Google Maps app that takes up most of the page. However, I need to reserve the top-most strip of space for a menu bar. How can make the map div automatically fill

6条回答
  •  一向
    一向 (楼主)
    2020-12-04 18:23

    The way to do it, apparently, is to use JavaScript to monitor the onload and onresize events and programmatically resize the filling div like so:

    Using jQuery:

    function resize() {
        $("#bottom").height($(document).height() - $('#top').height());
    }
    

    Using plain JavaScript:

    function resize() {
        document.getElementById("bottom").style.height = (document.body.clientHeight - headerHeight) + "px";
    }
    

    Edit: and then bind these to the window object.

提交回复
热议问题