实现水平垂直居中的方式
1.利用绝对定位
.parent {
position: relative;
}
.child {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%)
}
2.绝对定位
.parent {
position: relative;
}
.child {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
}
3.利用flex布局
.parent {
display: flex;
justify-content: center;
align-items: center;
}