代码之家  ›  专栏  ›  技术社区  ›  vtortola

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

  •  4
  • vtortola  · 技术社区  · 16 年前

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

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

    t get it work.At his moment I'm using 最小高度 , but how could I use the height:100%` ? 我喜欢的是页脚总是可见的,你可以滚动内容。

    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 回复  |  直到 6 年前
        1
  •  2
  •   Warty    16 年前
    /**
     * 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%的浏览器视窗。

        3
  •  1
  •   Riley    16 年前
    <!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

        4
  •  1
  •   Saladin Akara    16 年前

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

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

    希望有帮助。

        5
  •  0
  •   Alec    16 年前

    我已经用了很多年了,仍然很管用:


    http://www.themaninblue.com/writing/perspective/2005/08/29/