<div class="box">垂直居中</div>
.box {
width: 100px;
height: 100px;
background: #FEE;
line-height: 100px;
}
<div class="box">垂直居中</div>
.box {
width: 100px;
background: #FEE;
padding: 50px 0;
}
<div class="container">
<div class="box">垂直居中</div>
</div>
.container {
width: 100px;
height: 100px;
background: #FEE;
display: table;
}
.box {
display: table-cell;
vertical-align: middle;
}
<div class="container">
<div class="box">垂直居中</div>
</div>
.container {
width: 100px;
height: 100px;
background: #FEE;
position: relative;
}
.box {
position: absolute;
top: 50%;
transform: translateY(-50%);
}
<div class="box">垂直居中</div>
.box {
width: 100px;
height: 100px;
background: #FEE;
display: flex;
align-items: center;
}