.box1 {
width: 100px;
height: 100px;
background-color: aqua;
}
/* 1. 絕對定位水準居中 */
.box1 {
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
margin: auto;
}
/* 2. 水準垂直居中(不知道盒子大小) */
.box1 {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
/* 3.居中(知道盒子大小) */
.box1 {
position: absolute;
top: 50%;
left: 50%;
margin: -50px 0 0 -50px;
}
/* 4.flex居中 */
.box1 {
display: flex;
align-items: center;
justify-content: center;
}