2012-05-28 41 views
0

我有一个粘脚页脚布局。问题在于主要中心内容的实际高度不正确。虽然它隐藏在页脚后面并且最终用户看不到这一点,但例如在居中放置地图时会引起问题。布局内容从粘脚注失算

如何缩短内容的高度,使其保持在页脚的上方,以便呈现真实的内容高度(同时保持100%)。举例来说,我在这里有一个工作示例: http://jsfiddle.net/mp8nr/43/

当您使用Firebug将鼠标悬停在元素上时,您会看到主内容实际上位于粘滞页脚的下方。我只需要移动它,而不是切断顶部,但我所有的尝试都失败了。我将不胜感激任何帮助。

enter image description here

回答

1

编辑:有超过一件事错了你的布局。这里有一个固定的版本: http://jsfiddle.net/Ym3YP/

好了,你还没有实际上实现一个棘手的注脚。您只需放置一个固定位置的页脚。当您使用固定或绝对定位时,所涉及的元素将从中抽取,这就是您的主内容div一直延伸到底部的原因。它没有看到或识别页脚正在阻挡!

下面是如何正确地实现粘性页脚避免这些问题:

Ryan Fait摘自:

样本HTML:

<html> 
    <head> 
     <link rel="stylesheet" href="layout.css" ... /> 
    </head> 
    <body> 
     <div class="wrapper"> 
      <p>Your website content here.</p> 
      <div class="push"></div> 
     </div> 
     <div class="footer"> 
      <p>Copyright (c) 2008</p> 
     </div> 
    </body> 
</html> 

样品CSS:

* { 
    margin: 0; 
} 
html, body { 
    height: 100%; 
} 
.wrapper { 
    min-height: 100%; 
    height: auto !important; 
    height: 100%; 
    margin: 0 auto -142px; /* the bottom margin is the negative value of the footer's height */ 
} 
.footer, .push { 
    height: 142px; /* .push must be the same height as .footer */ 
} 

/* 

Sticky Footer by Ryan Fait 
http://ryanfait.com/ 

*/ 

另外,看看这个Smashing Magazine article它深入地解释了CSS流程的基础知识,它可以帮助你避免这些类型的问题。对于任何进入CSS的人来说,这是一个必读内容,并将在未来为您节省很多麻烦。

+0

我花了很多时间和精力在我的布局上,也许我的术语错了......有没有办法解决我得到的而不是从头开始? – TruMan1

+0

当然,让我试着修理你的jsfiddle。 – roflmao

+0

在这里你可以先生:http://jsfiddle.net/Ym3YP/ – roflmao