set div height使用jquery(stretch div height)

前端之家收集整理的这篇文章主要介绍了set div height使用jquery(stretch div height)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有3个div与ids头,内容和页脚。页眉和页脚具有固定的高度,并且它们的样式在顶部和底部浮动。我想使用jquery自动计算中间内容高度。如何使这可能?
#header {
    height: 35px;
    width: 100%;
    position: absolute;
    top: 0px;
    z-index: 2;
}
#footer {
    height: 35px;
    width: 100%;
    position: absolute;
    bottom: 0px;
    z-index: 2;
}

提前致谢…:)

blasteralfred

解决方法

你可以这样做:
$(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

});

见这里的小提琴:http://jsfiddle.net/maniator/JVKbR/
demo:http://jsfiddle.net/maniator/JVKbR/show/

原文链接:https://www.f2er.com/css/221133.html

猜你在找的CSS相关文章