【问题标题】:Keeping footer visible and height 100% in CSS在 CSS 中保持页脚可见和高度 100%
【发布时间】:2010-05-21 08:46:27
【问题描述】:

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

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

我想使用 100% 的高度,就像我可以使用宽度一样,但我只是 dont get it work.At his moment I'm using min-height, but how could I use the height: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;
}

【问题讨论】:

  • 要粘贴代码,您需要将 all 行缩进 4 个空格,而不仅仅是第一行 - 您可以通过突出显示代码块轻松做到这一点然后点击输入框上方的小“101010”按钮(它在图片的左侧和引号的右侧)。
  • 谢谢!下次我会记住的,也感谢编辑。

标签: html css height


【解决方案1】:
/**
 * 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%。

【讨论】:

    【解决方案2】:

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

    【讨论】:

      【解决方案3】:
      <!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

      技巧是将 html,body 扩展至 100%

      【讨论】:

        【解决方案4】:

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

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

        希望对你有帮助。

        【讨论】:

          【解决方案5】:

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

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

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2011-06-03
            • 2015-02-09
            • 1970-01-01
            • 2023-03-29
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2011-04-14
            相关资源
            最近更新 更多