2011-04-03 65 views
1

我有顶部标题<div id="header"></div>,中间部分<div id="content"></div>和底部页脚<div id="footer"></div>自动调整div高度以填充空间 - CSS

页眉和页脚的高度固定为50px。我想修复页眉和页脚在顶部和底部的位置,我想拉伸中间部分(内容)以填充剩余空间。

我该怎么做?

回答

2

我通过定义如下的样式来制作它;

#header, #content, #footer { 
    position: absolute; 
} 
#header{ 
    top: 0; 
    width: 100%; 
    height: 50px; 
    left: 0; 
    right: 0; 
} 
#content { 
    top: 50px; 
    left: 0; 
    right: 0; 
    bottom: 50px; 
} 
#footer { 
    bottom: 0; 
    left: 0; 
    right: 0; 
    width: 100%; 
    height: 50px; 
} 

你可以看到我的小提琴here

感谢@ rocky3000和@Mika支持:)

3

您可以使用位置:页脚和页眉的绝对位置,然后将页脚放置在底部:0px。我会做这种方式:

#header { 
    height: 50px; 
    width: 100%; 
    position: fixed; 
    top: 0px; 
    z-index: 2; 
} 

#footer { 
    height: 50px; 
    width: 100%; 
    position: fixed; 
    bottom: 0px; 
    z-index: 2; 
} 

#content { 
    top: 50px; 
    width: 100%; 
    position: absolute; 
    z-index: 1; 
} 
+1

嗯..我现在觉得这是不是一个好soloution。 :) – rocky3000 2011-04-03 16:17:26

+0

真的!我在这边乱搞,但completeley忘了'保证金: - 价值' – 2011-04-03 16:20:08

+0

我只是改变了从绝对到固定的邮政。 – 2011-04-03 16:20:46

0

搜索粘页脚LINK这里计算器或与谷歌和问题走了。

+0

它只是在页脚的情况下..我想在页眉和页脚之间伸展div – 2011-04-03 16:55:23

+0

为什么要扩展页眉和页脚之间的div?请你能解释一下吗? – Mika 2011-04-03 18:13:36

+0

我只是想自动调整内容..这就是... – 2011-04-04 15:10:17