1.已知块级元素的宽和高,使用绝对定位absolute和外边距实现水平垂直居中
position: absolute;
top:50%;
left: 50%;
margin-top: -(width/2)px;
margin-left: -(width/2)px;
2.使用弹性布局
/*父元素*/
display: flex;
justify-content: center;
align-items: center;
/* 或 */
/* 父元素 */
display: flex;
/* 子元素 */
margin: auto;
3.使用绝对定位+ transform
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
4.未知子元素的宽和高,设置其样式属性
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
margin: auto;