【发布时间】:2016-06-21 22:23:39
【问题描述】:
我想要一个粘性页脚,但我也希望我的主 div 在高度的页脚之前结束,但是如果您的边距为负并且我不知道为什么,包装器不会像往常一样向上移动。即使有最小高度,我也应该能够将其向上移动。当我增加负边距时,什么也没有发生。基本上我只需要我的包装器是 100% 的高度减去页脚的高度。感兴趣的 div 是具有蓝色背景的 div。现在我的侧边栏非常好(或者至少应该如此),因为它在黑色页脚之前结束。
html {
height: 100%;
}
body{
height: 100%;
margin:0;
font-family: courier;
font-size: 22px;
color: white;
background-color: #99ff33;
}
#wrapper{
position: relative;
margin-left: auto;
margin-right: auto;
width: 85%;
background-color: blue;
min-height: 100%;
height: calc(100vh-130px);
margin-bottom: -130px;
}
#wrapper:after{
content: "";
display:block;
}
#footer, #wrapper:after{
height: 130px;
}
.wrap {
margin: 0 auto;
width: 100%;
display: flex;
align-items: center;
flex-wrap: nowrap;
}
.sub {
padding: 12px;
width: 32%;
height: 100px;
color: white;
border-right: solid white 1px;
}
.sub:last-child{
border: 0px;
}
#sidebar{
float:left;
background-color: yellow;
height:calc(100vh - 130px);
width: 7.5%;
border: 1px solid blue;
}
#footer {
display: flex;
height: 130px;
width: 100%;
background-color: black;
clear: both;
}
<div id="sidebar"></div>
<div id="wrapper"></div>
<div id="footer">
<div class="wrap">
<div class="sub"></div>
<div class="sub"></div>
<div class="sub"></div>
</div>
</div>
【问题讨论】: