html - 将页脚贴在底部

标签 html css sticky-footer

我知道这是一个讨论很多的话题。但即使阅读了很多相关帖子,我仍然没有真正弄清楚我需要什么。

我遇到的问题是绝对位置 div 不固定在页脚上。我有一个单页网站。

这是我网站的简化代码:

HTML:

    <div id="e1">hi</div>
    <div id="e2">hi</div>
    <div id="e3">
    <div id="footer">My beautifull footer thingy</div>
    </div>

CSS:

body, html {

margin: 0 0 0 0;
padding: 0 0 0 0;
    width:100%;
height:100%;

    #e1 {height:100%; width:100%; background:#ff9000; }
    #e2 {height:100%; width:100%; background:#000;}
    #e3 {height:100%; width:100%; background:#ff9000;}

#footer {
text-align:center;
line-height:80px;
height:300px;
width:100%;
position:absolute;
background:#fff;
}

what I want

jsfiddle:http://jsfiddle.net/skunheal/4LXLZ/1/

我知道解决方案之一是添加

顶部:300%; 边距顶部:-300px;

但这不是我想要的,因为有一个 cms 主干,我无法判断有多少页面处于事件状态。所以我需要一些将自己设置为他的 parent 的东西(在这种情况下为#e3)

我考虑过的另一个解决方案是在计算有多少页面处于事件状态后使用 javascript 更改 css。但我认为这将是一个临时解决方案,应该更容易,对吧?

有人知道一个简单的 css 修复方法吗?

问候

最佳答案

可以设置相对于eX的位置

#e3 {height:100%; width:100%; background:#ff9000; position : relative}

example

关于html - 将页脚贴在底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20705863/

相关文章:

css - 如何在范围输入上垂直居中标签

html - 如何使 CSS 网格元素像 Flexbox 元素一样匹配父级的高度

html - 使用 <p> 的 ckeditor 换行符

css - 粘性页脚 Bootstrap 4

css - 如何在CSS中将页脚贴在底部?

html - 代码帮助!我想覆盖一个部分的背景和悬停颜色

javascript - 在 JavaScript 中派生

html - 禁用悬停在特定的 div 上

html - 如果文本溢出 = 它转到下一行

css - 将页脚固定在底部在 Chrome 中不起作用(在 IE、Firefox、Safari 中有效)