0

我一直在尝试各种技术来实现 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;
}

谢谢!

4

1 回答 1

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>
于 2013-05-07T01:04:30.230 回答