我尝试了很多方法,在搜索和工作三天后没有成功。
HTML:
<div id="wrapper">
<div id="header"></div>
<div id="container">
<div id="containertable">
<div id="leftbar"></div>
<div id="contents"></div>
<div id="rightbar"></div>
</div>
</div>
<div id="footer"></div>
</div>
CSS:
<style>
html{
overflow-y: scroll;
}
html,
body {
margin:0 auto;
padding:0;
height:100%;
width: 1024px;
}
#wrapper {
min-height:100%;
position:relative;
background: blueviolet;
}
#header {
background:#ff0;
width: 1024px;
height: 70px;
}
#container {
padding-bottom:60px; /* Height of the footer */
display: table;
}
#containertable{
width: 1024px;
display: table-row;
}
#leftbar, #rightbar{
width: 170px;
height: 100px;
display: table-cell;
background: brown;
}
#contents{
width: 684px;
height: 200px;
display: table-cell;
background: burlywood;
}
#footer {
width: 1024px;
position:absolute;
bottom:0;
width:100%;
height:60px; /* Height of the footer */
background:#6cf;
}
使用上面的代码和其他版本,我能够得到第1和第2个案例,但是我无法使列保持100%高度并且相等并将页脚推到页面底部。
在下图中,我正在寻找所有情况下的第三种情况。
Three different cases of pushing the footer div to the bottom of the page
答案 0 :(得分:0)
Martin Turjak给出了下面的解决方案,这对我来说非常有用。
的jsfiddle
http://jsfiddle.net/yellowandred/LznnG/5/
HTML:
<div class="wrapper">
<div class="column1"><a href="#">Test</a></div>
<div class="column2">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div>
<div class="spacer"></div>
<div class="footer">Footer</div>
</div>
CSS:
html, body {
width:100%;
height:100%;
margin:0;
padding:0;
text-align:center;
}
.wrapper {
position:relative;
min-height:100%;
width:80%;
margin:0 auto;
font-size:0px;
}
.wrapper div {
font-size:16px;
}
.column1, .column2 {
float:left;
margin-bottom:30px;
height:100%;
bottom:0;
}
.column1::before, .column2::before {
position:absolute;
content:'';
top:0;
bottom:0;
background:pink;
right:0;
z-index:-1;
}
.column1::before {
background:green;
left:0;
}
.column2::before {
background:blue;
left:30%;
}
.column1 {
width:30%;
}
.column2 {
width:70%;
}
.spacer {
position:relative;
clear:both;
}
.footer {
position:absolute;
height:30px;
bottom:0;
width:100%;
background:orange;
}