html - 如何在绝对容器底部放置粘性页脚

标签 html css sass haml sticky-footer

我的整个网站容器是页面居中的黑色背景上的白色框。 为此,内容可以调整我必须设置的框的大小:

.container {
  position: absolute;
  background-color: white;
  min-height: 90%;
  top: 5%;
  width: 95%;
  left: 2.5%;
}

尝试在此处添加页脚如下所示:

footer {
  margin-left: auto;
  margin-right: auto;
  width: 85%;
  text-align: center;
  height: 2.4em;
  border-top: 1px solid black;
}

为了将页脚放到底部,我假设我必须为实际内容定位容器

%header
%section.content /<----
%footer

将最小高度设置为 100%,但这没有用。

这是一个 fiddle :http://jsfiddle.net/a6QTv/1/

最佳答案

使用 Sticky Footer来自 CSS-Tricks 的技术:

<div class="page-wrap">
    Content!  
</div>

<footer class="site-footer">
    I'm the Sticky Footer.
</footer>

<style type="text/css">
* {
  margin: 0;
}
html, body {
  height: 100%;
}
.page-wrap {
  min-height: 100%;
  /* equal to footer height */
  margin-bottom: -142px; 
}
.page-wrap:after {
  content: "";
  display: block;
}
.site-footer, .page-wrap:after {
  /* .push must be the same height as footer */
  height: 142px; 
}
.site-footer {
  background: orange;
}
</style>

关于html - 如何在绝对容器底部放置粘性页脚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22317160/

相关文章:

php - 在同一页面中通过html表单向数据库插入数据

javascript - 如何动态地将选中的复选框元素添加到 Div 中?

javascript - 避免单词 split

css - 在 bootstrap 3 中重新排序行

css - 为什么 scss 中的 $rotation 变量不在过滤器 : progid:DXImageTransform. Microsoft.BasicImage 中解析

css - 如何在 sass 中将 .css 文件 @import 为 .scss 文件?

javascript - Cordova 输入类型数字 maxlength 在 android 中不起作用?

html - Css 使用颜色从继承颜色到另一个属性

php - 在 PHP 中将社交图标添加到标题

css - 自定义元素上的 FontAwesome 位置