粘滞页脚的问题

时间:2013-05-07 00:30:18

标签: css footer fixed sticky-footer overlapping

我一直在尝试各种技术来实现Ryan Fait的Sticky Footer技术,但似乎都没有。当浏览器垂直挑战时,我的页脚内容总是与我的主要内容重叠。可能是因为我有很多固定定位的DIV嵌套在页脚内。当我将这些DIV包裹在父DIV(#footer)周围时,这个父DIV似乎甚至不会出现,我也不能应用它来控制它的位置(以及其中的内容)。

HTML:

<body>
<div class="wrapper">
<div id="content"> Juicy stuff goes here</div>
<div class="push"></div>
<div class="footer">

     <div id="print_blank"></div>
     <div id="logo"></div>
     <div id="nav_bar"></div>
     <div id="footerarea">Contains other Text</div> 

</div><!-- Footer Area -->
</body>

CSS:

.wrapper {
    min-height: 100%;
    height: auto !important;
    height: 100%;
    margin: 0 auto -240px;
}
.footer, .push {
    height: 240px;
}
#print_blank {
    padding-top: 0px;
    bottom: 160px;
    position: fixed;
    z-index: 11000;
    width: 100% !important;
    text-align: center;
    min-width: 980px;
}
#logo {
    width: 180px;
    padding-top: 5px;
    bottom: 86px;
    position: fixed;
    z-index: 9999999;
    left: 45px;
}
#nav_bar {
    padding-top: 0px;
    bottom: 77px;
    position: fixed;
    z-index: 99999;
    width: 100% !important;
    text-align: center;
    min-width: 980px;
}
#footerarea {
    bottom: 0px;
    position: fixed;
    width: 100%;
    padding-top: 20px;
    background-color: #F16924;
    height: auto;
    text-align: justify;
    min-width: 960px;
    z-index: 999999;
}

谢谢!

1 个答案:

答案 0 :(得分:1)

这是一种更好的方法:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">

<style media="all">
html, body {height: 100%; margin: 0; padding: 0;}

* html #outer {/* ie6 and under only*/
    height:100%;
}

.wrapper {
    min-height: 100%;
    margin: -240px auto 0;
}

.content {padding-top: 240px;}

.footer {
    height: 240px; background: #F16924;
}

</style>

</head>
<body>

<div class="wrapper">
    <div class="content">Juicy stuff goes here</div>
    <div class="push"></div>
<!-- end wrapper --></div>
<div class="footer"></div>

</body>
</html>

粘性页脚的限制是页脚必须保持固定高度。但只要你小心,你在那里的元素不应该影响布局。

编辑:这是一个包含页脚元素的修订模板:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">

<style media="all">
html, body {height: 100%; margin: 0; padding: 0;}

* html #outer {/* ie6 and under only*/
    height:100%;
}

.wrapper {
    min-height: 100%;
    margin: -240px auto 0;
}

.content {padding-top: 240px;}

.footer {
    height: 240px; background: #F16924; position: relative;
}

#print_blank {
    padding-top: 0px;
    bottom: 160px;
    position: absolute;;
    z-index: 11000;
    width: 100% !important;
    text-align: center;
    min-width: 980px;
}
#logo {
    width: 180px;
    padding-top: 5px;
    bottom: 86px;
    position: absolute;;
    z-index: 9999999;
    left: 45px;
}
#nav_bar {
    padding-top: 0px;
    bottom: 77px;
    position: absolute;;
    z-index: 99999;
    width: 100% !important;
    text-align: center;
    min-width: 980px;
}
#footerarea {
    bottom: 0px;
    position: absolute;
    width: 100%;
    padding-top: 20px;
    background-color: #F16924;
    height: auto;
    text-align: justify;
    min-width: 960px;
    z-index: 999999;
}

</style>

</head>
<body>

<div class="wrapper">
    <div class="content">Juicy stuff goes here</div>
    <div class="push"></div>
<!-- end wrapper --></div>
<div class="footer">
    <div id="print_blank"></div>
    <div id="logo"></div>
    <div id="nav_bar"></div>
    <div id="footerarea">Contains other Text</div>

</div>

</body>
</html>