set div height using jquery (stretch div height)

前端 未结 6 1959
抹茶落季
抹茶落季 2020-12-04 17:37

I have 3 divs with ids header, content and footer. Header and footer has fixed height and they are styled to float on top and bottom.

6条回答
  •  长情又很酷
    2020-12-04 18:24

    well you can do this:

    $(function(){
    
        var $header = $('#header');
        var $footer = $('#footer');
        var $content = $('#content');
        var $window = $(window).on('resize', function(){
           var height = $(this).height() - $header.height() + $footer.height();
           $content.height(height);
        }).trigger('resize'); //on page load
    
    });
    

    see fiddle here: http://jsfiddle.net/maniator/JVKbR/
    demo: http://jsfiddle.net/maniator/JVKbR/show/

提交回复
热议问题