HTML粘滞页脚问题

时间:2011-09-21 04:20:22

标签: html css

尝试实施“粘性”页脚,但它没有按计划运行。它抛出它在底部,并在第一次滚动它按预期工作(除了它显示内部滚动条)。当向上滚动时,粘贴页脚不会立即消失,它需要几个卷轴然后它似乎回到“底部”。所以我的问题是我如何始终将页脚保持在底部并消除内部滚动条。我想知道我的绝对定位是否对主要内容有问题。这个div的高度可以扩展。

Problem Screenshot

以下是代码:

<div id="page-wrap">
  <div id="main-content>
    <div id="main-content-inner></div>
  </div>
  <div class="footerpush"></div>
</div>
<div id="footer">copyright info</div>


#page-wrap {
width:100%;
min-height:100%;
height:auto;
height:100%;
margin-bottom:-20px;
position:relative;
overflow:auto;

}
#main-content {
width: 100%;
height:100%;
margin-left: -295px;
position:relative;
}
#main-content-inner {
left: 560px;
border-radius:8px;
border-style:solid;
border-width:2px;
border-color:#53D8FF;
padding:20px;
padding-bottom:0;
background-color:#000000;
position:absolute;
top:100px;
min-width:60%;
max-width:60%;
}
#footer {

text-align: right;
padding-top: 20px;
padding-bottom: 20px;
padding-right: 20px;
color: #A7A9AC;
font-size: 12px;
height:20px;

}

.footerpush
{
height:20px;
}

如果我从页面换行中删除溢出自动,则页脚实际上会移动到页面换行div的底部。所以看来,由于我绝对的主要内容 - 内在是绝对的,它正在我的包装外扩展?如果我在页面换行的高度上设置一个固定值,页脚将按原样移动到底部。所以这是一个真正的问题,即使内容可扩展,如何将页脚保持在页面底部?

进一步的研究表明,当我在页面换行中设置溢出隐藏时,我的绝对内容“main-content-inner”被切断了。如何将页面包装的高度扩展到main-content-inner的高度,无论它是什么?

3 个答案:

答案 0 :(得分:0)

试试这个:

重写您的HTML代码:

<div id="page-wrap">
  <div id="main-content">
    <div id="main-content-inner">
    </div>
  </div>
  <div class="footerpush"></div>
  <div id="footer">copyright info</div>
</div>

并重写您的CSS文件样式属性:

html,body
{   height:100%;
    padding:0;
    margin:0;
}
#page-wrap {
width:100%;
min-height:100%;
position:relative;
overflow:auto;

}
#main-content {
    background:#FF0;
    padding-bottom:40px;
}
#main-content-inner {

border-radius:8px;
border-style:solid;
border-width:2px;
border-color:#53D8FF;
padding:20px;
padding-bottom:0;
background-color:#000000;
}
#footer {

text-align: right;
color: #A7A9AC;
font-size: 12px;
height:20px;
position:absolute;
bottom:0;
width:100%;
}

.footerpush
{
    position:absolute;
    bottom:20px;
    height:20px;
    width:100%;
}

答案 1 :(得分:0)

对我而言,这个网站是如何将页脚粘贴到网页末尾的最佳示例。

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

答案 2 :(得分:0)

在我回答here时,您可以使用http://www.cssstickyfooter.com/

<!DOCTYPE html>
<html>
    <head>
        <style type="text/css">
            html, body {
                height: 100%;
                padding: 0;
            }

            #wrap {
                min-height: 100%;
            }

            #main {
                overflow:auto;
                padding-bottom: 150px; /* must be same height as the footer */
            }

            #footer {
                position: relative;
                margin-top: -150px; /* negative value of footer height */
                height: 150px;
                clear:both;
            } 

            /*Opera Fix*/
            body:before {
                content:"";
                height:100%;
                float:left;
                width:0;
                margin-top:-32767px;/
            }
        </style>
        <!--[if !IE 7]>
        <style type="text/css">
            #wrap {display:table;height:100%}
        </style>
        <![endif]-->
    </head>
    <body>
        <div id="wrap">
            <div id="main">
                <div id="content">
                    <!-- Main content here -->
                </div>
            </div>
        </div>
        <div id="footer">
            <!-- Footer content here -->
        </div>
    </body>
</html>
  

您可以在此处查看一个有效的示例:http://jsfiddle.net/dZDUR/

     

将右侧“结果”窗格调整为比文本更短/更高   看到滚动条出现/消失。

     

根据CSS Sticky Footer how-to,您可以插入法线   main div内的'column'布局。