首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Content DIV中停止粘性页脚

如何在Content DIV中停止粘性页脚
EN

Stack Overflow用户
提问于 2013-04-28 12:32:50
回答 3查看 3K关注 0票数 0

我一直在调整我的粘性脚注,希望在它到达#body div时阻止它,但到目前为止,我还没有成功。在大多数情况下,它通常不会涵盖内容,但是on this page,它通常会涵盖内容。

如果可能的话,我想把它贴在窗口的底部,但我唯一能想到的其他解决方案就是固定位置。有什么建议吗?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2013-04-28 13:27:55

你可以通过多种方式来应用固定位置/粘性页脚。一种选择是只使用CSS,作为Twitter Bootstraps Sticky Footer example。这可能是最简单的实现。

代码语言:javascript
复制
  /* The html and body elements cannot have any padding or margin. */
  html,body { height: 100%; }

  /* Wrapper for page content to push down footer */
  #wrap {
    min-height: 100%;
    height: auto !important;
    height: 100%;
    margin: 0 auto -100px; /* Negative indent footer by it's height */
  }

  /* Set the fixed height of the footer here */
  #push,#footer{ height:100px }
  #footer {}
票数 1
EN

Stack Overflow用户

发布于 2013-04-28 13:15:17

我不确定你想要的结果,但可能你需要的就像:

代码语言:javascript
复制
#footer {
  position: fixed;
  bottom: 0;
  left:0;
  right:0;
}
票数 0
EN

Stack Overflow用户

发布于 2013-04-28 13:49:02

根据Ryan Fait的说法,您可以在文档layout.css中使用以下CSS:

代码语言:javascript
复制
* {
    margin: 0;
}
html, body {
    height: 100%;
}
.wrapper {
    min-height: 100%;
    height: auto !important;
    height: 100%;
    margin: 0 auto -4em; /*-4em represents the height of the footer */
 }
 .footer, .push {
    height: 4em;
 }

以及下面的HTML标记,它实际上很容易实现,并且可以在所有主要浏览器中使用。

代码语言:javascript
复制
<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>Website Footer Here.</p>
    </div>
</body>
</html>

我以前实现过它,它可以完美地使用页脚,无论是在页面的底部,还是在内容的底部,而且它根本不需要jquery或javascript。

为了响应kurzweilguy的comment,推送使它可以使页脚位于100%高度,这自然会将页面扩展为具有滚动条,因此为了应对它,您可以在页面上设置负边距以使其恢复到适合页面底部的大小。darcher引用的页脚使用相同的页脚。这是一个编译得非常好的页脚!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16259636

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档