html - 如何将页脚移动到页面底部?

标签 html css sticky-footer

网址: http://test.getfamo.us/

问题: 当您向下滚动时,我喜欢页眉如何保持在页面顶部的位置,但是对于页脚,如果它只在您一直滚动到页面底部(因此位置不像现在那样固定在适当的位置,而是在页面的最底部)。

这是与页脚关联的 CSS:

#foot{
left:0px;
right:0px;
color:white;
position:fixed;
height:50px;
background-color:#444444;
width:100%;
margin-bottom:0px;
bottom:0px;
margin-right:0px;
z-index:103;
}

#foot a{
height:50px;
width:75px;
float:left;
color:white;
text-align:center;
text-decoration:none;
line-height:25px;
 }

 #foot p{
position:absolute;
width:150px;
height:50px;
right:0px;
margin-bottom:0px;
margin-right:0px;
margin-top:0px;
bottom:0px;
top:0px;
}

非常感谢大家!希望它是一个简单的修复。 如果需要,还可以在此处获得完整的 CSS:http://test.getfamo.us/css/

最佳答案

好的,我给了你链接,但如果你遇到问题,请看看这个。使用您的代码和我给您的链接,我们可以创建它。

HTML:

<div class="page-wrap">
    <div id="fillspace"></div>
</div>
<div id="foot"></div>

CSS:

/* Your code */
#foot {
    left:0px;
    right:0px;
    color:white;
    height:50px;
    background-color:#444444;
    width:100%;
    margin-bottom:0px;
    bottom:0px;
    margin-right:0px;
    z-index:103;
}
#foot a {
    height:50px;
    width:75px;
    float:left;
    color:white;
    text-align:center;
    text-decoration:none;
    line-height:25px;
}
#foot p {
    position:absolute;
    width:150px;
    height:50px;
    right:0px;
    margin-bottom:0px;
    margin-right:0px;
    margin-top:0px;
    bottom:0px;
    top:0px;
}

/* New Code */
 html, body {
    height: 100%;
    margin: 0;
}
.page-wrap {
    min-height: 100%;
    /* equal to footer height */
    margin-bottom: -50px;
}
.page-wrap:after {
    content:"";
    display: block;
}
#foot, .page-wrap:after {
    /* .push must be the same height as footer */
    height: 50px;
}
#fillspace {
    width: 100%;
    height: 1000px;
    background: #ddd;
}

所以把你的代码和我给你的链接里的代码放在一起。然后我们拿走你的 position: fixed 并将页脚的正确高度设置为 #foot, .page-wrap:after.page-wrap。就这样,一切都完成了。查看演示并试用它。

内容:

DEMO HERE

没有内容:

DEMO HERE

关于html - 如何将页脚移动到页面底部?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21748911/

相关文章:

css - 为什么要在主 div 而不是其父 div 中添加填充,wrap?

php - Laravel Autoprefixer 不能在 webpack 中工作

javascript - 如何为标签输入创建自动完成框?

CSS Sticky Footer - 如果你在页面上绝对定位了 div 怎么办?

javascript - 使用位置属性使用图标

html - 有没有办法阻止 Outlook 破坏 <div> 的填充

css - 如何让页脚停留在网页底部?

javascript - 在单个 HTML 页面中绘制多个 HTML Canvas 元素

javascript - 使用 HTML5 + Javascript 将数据字符串保存为文件,而不使用 URI

jquery - 如何在焦点输入的同一父级中滑动类