2013-07-14 80 views
2

我一直在试图让div伸展到我的页脚,并取得了有限的成功。我已经使用jQuery做这个尝试,但仍存在一些问题:如何垂直拉伸div到页脚,并拉伸以适应内容?

<script type='text/javascript'>//<![CDATA[ 
$(window).load(function(){ 

$(window).resize(function(){ 
var height = $(this).height() - $("#banner-wrapper").height() - $("#footer-wrapper").height() 
$('#content').height(height); 

}) 

$(window).resize(); //on page load 

});//]]> 

</script> 

这绵延在div下到尾,但问题是,它立足的窗口大小的高度。如果您的内容延伸过去,#content div不会拉伸以适应内容。

http://matthewdail.com/staging/
在这里你可以看到jQuery做它的工作,并完美地扩展#content div,但它没有扩展到适合内容。

我也尝试了一些比较常见的CSS技巧的,如:

html,body{ 
height:100%; 
} 

#content{ 
width:100%; 
margin:0 auto -120px; 
float:none; 
min-height:100%; 
height:auto !important; 
height:100%; 
} 

我到处找,但不能找到解决这个。有人有主意吗?

回答

0

你是否想要内容div向下延伸,以便它推动页脚到底部电子窗口?你会关闭using something like this更好:

html { 
    position: relative; 
    min-height: 100%; 
} 
body { 
    margin: 0 0 100px; /* bottom = footer height */ 
} 
footer { 
    position: absolute; 
    left: 0; 
    bottom: 0; 
    height: 100px; 
    width: 100%; 
} 

如果身体没有足够的内容页脚仍然停留在底部。 Demo here