19

有没有办法设置布局,使页眉为 50 像素,正文为 100%,页脚为 50 像素?

我希望身体至少用完整个观看区域。我希望页脚和页眉始终显示在屏幕上

4

3 回答 3

18

我在 jsfiddle 中创建了一个示例:

更新的 JsFiddle:http: //jsfiddle.net/5V288/1025/

HTML:

<body>
    <div id="header"></div>
    <div id="content"><div>
        Content 
    </div></div>
    <div id="footer"></div>
</body>

CSS:

html { height: 100%; }
body {
    height:100%;
    min-height: 100%;
    background: #000000;
    color: #FFFFFF;
    position:relative;
}
#header {
    height:50px;
    width:100%;
    top:0px;
    left:0px;
    background: #CCCCCC;
    position:fixed;
}
#footer {
    height:50px;
    width:100%;
    bottom:0px;
    left:0px;
    background: #CCCCCC;
    position:fixed;
}
#content {
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
    height:100%;
    padding: 0 20px;
}
#content > div {
    padding: 70px 0;
}

没有边框框的内容将是高度 100% + 140px 填充。使用边框框,内容高度将为 100%,并且填充将在内部。

于 2012-04-19T12:56:38.293 回答
4

只是对 Andreas Winter 解决方案的修复:

http://jsfiddle.net/5V288/7/

*使用它的解决方案,如果内容大于可用窗口区域,您将遇到问题。

于 2012-04-19T13:17:44.150 回答
4

我认为您正在寻找的是“多个绝对坐标”。A List Apart 在这里有一个解释,但基本上,您只需将主体的位置指定为绝对位置,并同时设置top: 50pxbottom: 50px

<body>
<style>
#header {
  position: absolute;
  height: 50px;
} 

#body {     
  position: absolute;
  top: 50px;
  bottom: 50px;
  background-color: yellow;
}

#footer {
  position:absolute;
  height: 50px;
   bottom: 0;
}
</style>
<div id="header">Header</div>
<div id="body">Content goes here</div>
<div id="footer">Footer</div>

http://www.spookandpuff.com/examples/absoluteCoordinates.html以更漂亮的方式展示了该技术。

于 2012-10-16T05:12:00.857 回答