粘性页脚& 100%高度 - 强制div获得100%高度

时间:2014-07-29 12:57:19

标签: css height sticky-footer

请看代码: http://jsbin.com/jeduvowa/1/

如何强制粉红色div获得100%高度(即使内容不足,div也应触摸页脚)

2 个答案:

答案 0 :(得分:0)

您必须将height: 100;设置为bodyhtmlcontent。 您正在height: 100%;覆盖height: auto !important;

或者,如果您希望内容成长,可以创建两个层。一个内容和第二个wirh背景。

答案 1 :(得分:0)

你可以这样做:

<强> HTML:

* {
    margin: 0;
}
html, body {
    height: 100%;
}
.header {
  background: red;
}
.wrapper {
    height: 100%;
    margin: 0 auto -40px;
    background: gray;
}
.content {
  width: 200px; 
  margin: 0 auto; 
  background: pink; 
  height: calc(100% - 18px); /*100% - the height of the header*/
}

.footer {
  background:green;
}
.footer {
    height: 40px;
}
相关问题