第一種,常用於垂直居中盒子的文字,需要知道盒子高度,行高不能設置百分比
text-align:center;
line-height:盒子本身高度
第二種,使用display:table和display:table-cell配合,兩個必須分別作用於父盒子和子盒子
display:table-cell;
vertical-align:middle;
第三種,使用flex布局,不需要知道寬高,寫在父盒子
display:flex;
justify-content:center;
align-item:center;
第四種,使用position定位
position:absolute;
top:0;
right:0;
bottom:0;
left:0;
margin:auto;
第五種,也是使用position定位
position:absolute;
top:50%;
left:50%;
transform:translate(-50%, -50%);