Resize div on browser resize

后端 未结 2 970
广开言路
广开言路 2021-01-07 02:59

I have a

which I want to display full screen, but I also need to incorporate a 60px high
and a 10px
相关标签:
2条回答
  • 2021-01-07 03:17

    Try this:

    $(window).resize(function(){
      $('#fullscreen').height($(document).height() - ($('#div1').height() + $('#div2').height()) + 'px');
    });
    

    Updated Based On Comment:

    I am using the jQuery in above code, you will have to download and include it in your page first.

    Once you have downloaded and included in your page, then use this code:

    $(function(){
        $(window).resize(function(){
          $('#fullscreen').height($(document).height() - ($('#div1').height() + $('#div2').height()) + 'px');
        });
    });
    
    0 讨论(0)
  • 2021-01-07 03:24

    One way to achieve this in some cases via just HTML and CSS is to have absolutely positioned div with it's top set to the 70px and every other direction set to 0px. Then every other side will adjust itself to the edges of the browser window.

    For example:

    <style type="text/css">
    #fullscreen {
        background-color: #0000FF;
        position: absolute;
        top: 70px;
        left: 0px;
        right: 0px;
        bottom: 0px;
    }
    </style>
    
    <div id="fullscreen">The Full Screen</div>
    
    0 讨论(0)
提交回复
热议问题