方法1:table-cell
.box1{ display: table-cell; vertical-align: middle; text-align: center; }
<div class="box box1"> <span>垂直居中</span> </div>
方法2:display:flex
.box2{
display: flex;
justify-content:center; //横
align-items:Center; //竖
}
原文地址:https://www.cnblogs.com/congxueda/p/9495475.html
时间: 2024-11-10 14:58:08