在CSS中保持页脚可见和高度100%

时间:2010-05-20 23:27:14

标签: html css height

我正在尝试创建一个非常简单的页面,其中包含容器,标题,左列和页脚:

<containter>
<header />
<content />
<leftBar />
<footer />
</containter>

我想使用100%的高度,因为我可以使用宽度,但我只是t get it work.At his moment I'm using min-height , but how could I use the身高:100%`?我喜欢的是页脚始终可见,您滚动内容。

当前CSS

body
{
    font-family: Verdana;
    font-size: 0.8em;
    background-color:#f1f1f1;
}

#container {
   border:solid 2px Black;
   position:absolute;
   left:10%;
   width:80%;
   margin:auto;
}

#header {
  height:20px;
  background: #DDDDDD;
}

#leftBar {
  width: 20%; 
  background: #669966; 
  min-height:600px;
  postion:absolute;
  top:20px;
  bottom:20px;
}

#content {
  float:right;
  background-color: #cdcde6;
  position:absolute;
  left:20%;
  right:0px;
  bottom:20px;
  top:20px;
  padding:5px;
}

#footer {
 position:absolute;
 height:20px;
}

5 个答案:

答案 0 :(得分:2)

/**
 * The following allows the usage of height=100% in body tag.
 * Creds to: http://apptools.com/examples/tableheight.php
 */
html,body
{
    margin    : 0;
    padding    : 0;
    height    : 100%;
    border    : none;
}

你需要这样做才能使html和body占据浏览器视口的100%。

答案 1 :(得分:1)

我不确定这是否正是您所要求的,但在css layout http://matthewjamestaylor.com/blog/perfect-multi-column-liquid-layouts方面它是一个很好的资源。它还有一篇文章解释了如何将其添加到容器中:http://matthewjamestaylor.com/blog/how-to-convert-a-liquid-layout-to-fixed-width

答案 2 :(得分:1)

<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
<style>
  html, body { margin: 0 auto; height: 100%; }
  #container { height: 100%; width: 80%; background: #e0e0e0; margin: 0 auto;}
</style>
</head>
<body>
  <div id="container">
  </div>
</body>
</html>

http://jsbin.com/uyezu

Trick是将html,body扩展为100%

答案 3 :(得分:1)

我实际上是在今天晚上自己解决了类似的问题,以下链接提供了完美的解决方案:

http://ryanfait.com/resources/footer-stick-to-bottom-of-page/

希望它有所帮助。

答案 4 :(得分:0)

我多年来一直在使用它,仍然很有效:

footerStickAlt:一种更健壮的页脚定位方法
http://www.themaninblue.com/writing/perspective/2005/08/29/