2012-01-09 90 views
1

我想:自动调整高度并在中间div滚动 - 可能吗?

<div style="height:100%"> 
    <div style="height:70px;">header</div> 
    <div style="overflow-y:scroll;">main</div> 
    <div style="height:60px;">footer, alw. at bottom parent-div</div> 
</div> 

实(PX)容器高度可在客户端窗口大小的改变DEP, 高度页脚和页眉的CSS-主题设置的。

所有的定位应该是相对的。 JS需要解决这个问题吗?

(试过高度:汽车的主,似乎没有任何效果。)

+1

'高度:汽车;'是一个'div'的默认行为。你只想让你的主div在窗口大小达到时滚动? – c4urself 2012-01-09 10:54:51

回答

2

您可以使用absolute定位,实现这个很容易,为什么要定位relative

#header, #main, #footer { 
    left: 0; 
    right: 0; 
    position: absolute; 
}  

#header { 
    top: 0; 
    height: 70px; 
    background-color: yellow; 
} 

#main { 
    top: 70px; 
    bottom: 60px; 
    background-color: lime; 
    overflow: auto; 
} 

#footer { 
    bottom: 0; 
    height: 60px; 
    background-color: red; 
} 

的jsfiddle:http://jsfiddle.net/Tg8g5/

+1

很棒,作品,谢谢。 – Teson 2012-01-10 13:46:33