【问题标题】:Sticky Footer failure粘性页脚失败
【发布时间】:2012-08-29 13:53:56
【问题描述】:

我正在尝试使页脚正确,但遇到了问题。我能够将页脚保持在页面底部,但很快意识到当窗口变小时,它最终会覆盖内容。我可以通过取消 position:absolute 来解决这个问题,但是如果我这样做,页脚将不再停留在页面底部。

我已经尝试了很多不同的方法来让它工作,但这是我目前正在研究的,我希望有人可以在这里提供一些建议..

CSS 代码:

html, body {
    margin: 0;
    padding: 0;     
    height:100%;
}
#wrapper {
    width:900px;
    background-color:#FAFAFA;
    min-height:100%;
    margin:0 auto -45px;
    height: auto !important;
    height:100%;
}
#content{
    margin-top:40px;
    float: left;
    padding-left:100px;
    padding-bottom:30px;
    overflow:auto;  
}
#footer{
    height:30px;
    bottom:0;
    background:#D2CFCF;
    width:900px;
    clear:both;
    position:absolute;
}

我最近在页脚中尝试了 margin-top:-30px 和 position:relative。使用上面的代码,页脚很好,位于底部,但在窗口变小时会覆盖内容。我能做什么?

HTML基本如下

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

【问题讨论】:

标签: css footer


【解决方案1】:

在页脚使用position: fixed; 规则,在&lt;body&gt; 标记上使用底部margin

http://jsfiddle.net/JGUYh/

BODY {
 margin: 0 0 60px 0; /* keep regular content clear of the footer */
}
#footer {
 position: fixed;
 width: 100%;
 height: 50px;
 bottom: 0px;
 background: #ccc;
 overflow: hidden;
}​

请注意,根据窗口大小,页脚有时会覆盖内容。但是滚动会显示任何隐藏的内容。

【讨论】:

  • 谢谢,我希望找到一些永远不会涵盖内容的东西,如果可能的话,我认为一定是这样吗?我要在 cmets 中尝试其他人的解决方案
猜你喜欢
  • 2013-05-02
  • 2012-08-11
  • 2013-02-23
  • 1970-01-01
  • 2012-12-28
  • 2014-09-09
  • 2012-04-10
  • 2011-08-14
  • 2017-11-04
相关资源
最近更新 更多