【问题标题】:Can't make footer stick to the bottom of the page无法使页脚粘在页面底部
【发布时间】:2013-01-22 00:59:25
【问题描述】:

smiths-heimannan.az 是我的网站。尝试了http://www.cssstickyfooter.com/ 的所有说明,但它对我不起作用(证明它不起作用http://smiths-heimann.az/?page=3)。请帮助我将页脚添加到页面底部并提前删除 2 个 div http://prntscr.com/2e2fp Thx 之间的空行

【问题讨论】:

  • 证明不会加载,至少对我来说不会。你能把你的基本 HTML 结构和 CSS 一起发布吗?
  • 对不起。试试这个链接smiths-heimann.az?page=3
  • 我已编辑您的帖子以获得新网址。
  • @Hristo 你在吗? smiths-heimann.az/?page=3 请检查错误代码。我仍然得到容器和页脚之间的差距

标签: html css footer sticky-footer


【解决方案1】:

您的#footer#wrap 内。粘性页脚代码有页脚外部 #wrap:

<div id="wrap">
    <div id="main">
        <div id="content">
        </div>
        <div id="side">
        </div>
    </div>
</div>

<div id="footer">
</div>

编辑

刚刚使用移动的页脚代码查看了您的网站。您在底部有一个间隙,如果您不想要它,可以通过使#footerheight 与页脚的margin-top 相同,但为正值来解决。

修改其他问题

在您的标题中,您有一个导航 ul 和几个类:sf-menusf-js-enabledsf-shadow。如果你把margin-bottom: 1em 去掉,这个差距就被消除了。

编辑到非拉伸背景问题

这还是很简单的,虽然它会稍微改变标题的透明度。

在您的 CSS 文件中找到 #containerbackground-image 并将其移动到 #wrap。澄清一下,#wrap 应该有这个 CSS:

#wrap 
{
    min-height: 100%;
    background: url("img/tff.png") 0 0 repeat;
}

#container 应该是这样的:

#container 
{
    min-width: 980px;
    width: 100%;
    overflow: auto;
    padding-bottom: 110px;
}

二次编辑非拉伸背景问题

好的。唷。我做的;我也删除了滚动条。

#footer设为:

#footer {
    background: -moz-linear-gradient(center top , #FFFFFF, #EEEEEE) repeat scroll 0 0 transparent;
    border-top: 1px solid #919191;
    clear: both;
    font-size: 10px;
    height: 110px;
    margin-top: -126px;
    padding-top: 5px;
    position: relative;
    text-align: center;
    width: 100%;
}

出现滚动条是因为边框和内边距为页脚添加了额外的高度,因此负边距实际上太小了。我已将其更改为-116px虽然这在 Firefox 中有效,但 OP 发现它在 Chrome 中无效。最终,使用经过编辑的图像来获得所需的功能。仅将此答案作为参考。

现在让#wrap这个:

#wrap {
    background: url("img/tff.png") repeat scroll 0 0 transparent;
    height: auto;
    margin-top: 100px;
    min-height: 100%;
    position: relative;
}

最后,让.header这个:

.header {
    background-image: url("img/nav/trans.png");
    color: white;
    height: 80px;
    top: -100px;
    padding-bottom: 10px;
    padding-top: 10px;
    text-align: center;
    position: relative
}

【讨论】:

  • 已更改并上传。 smiths-heimann.az/?page=3 试试这个。 css 出现了其他问题,div 之间出现了新的空行prntscr.com/2e2fp
  • @Tural... 那是因为您在页脚上有 margin-top: -150px;。它应该是页脚的高度 + 其他杂项高度,例如从边框开始。
  • 您是否阅读了我的回答中的编辑其他问题部分?我仍然可以在您的ul 上看到margin-bottom
  • @Tural... + 其他杂项高度/边距/填充。正如 JamWaffles 提到的,你有 1em 的边距-底部...
  • @Tural: Moar editz!看看我的回答中的编辑到非拉伸背景问题
【解决方案2】:
 margin-top: -150px;

丢掉那个 CSS

【讨论】:

  • -1 a) 如果您在谈论#footer,它应该在那里并且b) 您在谈论的margin 是模棱两可的。请在发布答案之前进行研究。 cssstickyfooter.com/using-sticky-footer-code.html
  • 好的,我想我应该得到-1 :) 当然不要删除整个#footer,它是必需的,而只是margin-top。顺便说一句,在发布我的答案之前,我确实访问了该网站并使用 firebug 禁用了该 CSS。
  • 我确实承认,我相当傲慢。我投了反对票,因为粘性页脚教程专门设置了负边距。至少我给出了一个反对的理由,嗯 :-)
  • 啊,谢谢你的解释,我只是需要进一步研究。嘿 SO 是学习东西的地方。
  • smiths-heimann.az/?page=3 请检查错误代码。我仍然得到容器和页脚之间的差距
猜你喜欢
  • 1970-01-01
  • 2014-08-13
  • 2011-06-30
  • 1970-01-01
  • 2016-05-01
  • 2012-10-19
相关资源
最近更新 更多