【问题标题】:Sticky footer redux粘性页脚还原
【发布时间】:2014-04-15 03:38:08
【问题描述】:

code pen

HTML

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

CSS

#header {
  background-color: red;
}

#body {
  background-color: orange;
}

#content {
  width: 500px;
  margin: 0 auto;
  background-color: yellow;
}

#footer {
  background-color: blue;
}

body {
  display: table;
  height: 100%;
  width: 100%;
}

#header,#footer,#body {
  display: table-row;
  height: 1px;
}

#body {
  height: auto;
}
#content {
  /* ??? */
}

html,body {
  margin: 0;
  padding: 0;
  height: 100%;
}

This answer 在只需要拉伸顶级 div 时提供了一些很好的解决方案,但在我的场景中,我可以让 #body(橙色 bg)拉伸但我需要 #content(黄色)拉伸一路向下。

我该怎么做?

【问题讨论】:

    标签: css sticky-footer


    【解决方案1】:

    演示 http://codepen.io/anon/pen/Bltbh

    #header {
      background-color: red;
    }
    
    #body {
      background-color: orange;
      height:100%;
    }
    
    #content {
      width: 500px;
      margin: 0 auto;
      background-color: yellow;
    }
    
    #footer {
      background-color: blue;
    }
    
    body {
      display: table;
      height: 100%;
      width: 100%;
    }
    
    #header,#footer,#body {
      display: table-row;
    }
    #header,#footer {
      height:1px;
    }
    
    #body {
      height: 100%;
    }
    #content {
      height: 100%;
    }
    
    html,body {
      margin: 0;
      padding: 0;
      height: 100%;
    }
    

    【讨论】:

    • 我尝试了一些非常相似的方法,但它导致滚动条出现在我的内容上。我尝试将overflow: visible 添加到#content,这似乎有效。
    猜你喜欢
    • 2013-02-23
    • 1970-01-01
    • 2012-12-28
    • 2014-09-09
    • 2012-04-10
    • 2011-08-14
    • 2017-11-04
    • 2012-05-14
    • 2014-03-08
    相关资源
    最近更新 更多