display:flex;
flex-direction: column;
justify-content:flex-end;
对于如下所示的容器 div
:
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html,
body {
height: 100%;
}
#container {
display: flex;
flex-direction: column;
justify-content: flex-end;
height: 100%;
border: 1px solid;
}
.box {
height: 50px;
width: 100%;
border: 1px solid;
}
#box1 {
background: dodgerblue;
}
#box2 {
background: orange;
}
#box3 {
background: lime;
}
<div id='container'>
<div id='box1' class='box'></div>
<div id='box2' class='box'></div>
<div id='box3' class='box'></div>
</div>
您需要指定父级和内容的相对高度,带有display:table-cell
属性的
display:table
属性的元素中。
HTML
<div>
<div>
<div></div>
<div></div>
<div></div>
</div>
</div>
CSS
html, body {
height:100%;
width:100%;
margin:0;
padding:0;
}
div {
display:table;
height:100%;
}
div div {
height:100%;
width:100px;
border:1px solid black;
display:table-cell;
vertical-align:bottom;
}
div div div {
display:block;
height:20px;
}
.s_div{
display: flex;
align-items: flex-end;
}