设置div高度使用jquery(伸展div高度)
我有3个ids header , content和footer div。 页眉和页脚有固定的高度,它们的样式可以浮在上面和下面。 我想用jQuery自动计算中间content高度。 我怎样才能使这可能? 
 #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/ 
 演示: http : //jsfiddle.net/maniator/JVKbR/show/ 
正确的方法是使用古老的CSS:
 #content{ width:100%; position:absolute; top:35px; bottom:35px; } 
而奖金是,你不需要附加到window.onresize事件! 一切都会随着文件重排而调整。 所有的四行CSS的低价格!
closures我的头顶上:
 $('#content').height( $(window).height() - $('#header').height() - $('#footer').height() ); 
你是这个意思吗?
你可以像下面这样绑定函数,而不是加载时的init
 $("div").css("height", $(window).height()); $(window).bind("resize",function() { $("div").css("height", $(window).height()); }); 
 $(document).ready(function(){ contsize();}); $(window).bind("resize",function(){contsize();}); function contsize() { var h = window.innerHeight; var calculatecontsize = h - 70;/*if header and footer heights= 35 then total 70px*/ $('#content').css({"height":calculatecontsize + "px"} ); }