我有1个父表单元格.t
和2个子块.ch1
和.ch2
:
HTML:
<div class="t">
<div class="ch1">1</div>
<div class="ch2">2</div>
</div>
CSS:
.t {
display: table-cell;
background-color:green;
height:200px;
width:200px;
}
.ch1 {
background-color:blue;
display: block;
}
.ch2 {
background-color:red;
display: block;
}
是否可以将
.ch2
推到底部,但将.ch1
放在顶部(如果使用vertical-align: bottom;
的.t
它将把两个块都推到底部)JSFiddle:
https://jsfiddle.net/hvz4cn69/
最佳答案
Flexbox可以做到这一点:
.t {
display: flex;
flex-direction: column;
background-color: green;
height: 200px;
width: 200px;
justify-content: space-between;
}
.ch1 {
background-color: blue;
display: block;
}
.ch2 {
background-color: red;
display: block;
}
<div class="t">
<div class="ch1">1</div>
<div class="ch2">2</div>
</div>
要么
.t {
display: flex;
flex-direction: column;
background-color: green;
height: 200px;
width: 200px;
}
.ch1 {
background-color: blue;
display: block;
}
.ch2 {
background-color: red;
display: block;
margin-top: auto;
}
<div class="t">
<div class="ch1">1</div>
<div class="ch2">2</div>
</div>