1,利用定位+margin:auto position: absolute; left right top buttom;0
2,利用定位+margin:负值 margin-left: -50px; margin-top: -50px; left: 50%;top: 50%;
3, 利用定位+transform left: 50%;top: 50%; top: 50%;
4, flex布局
5, grid布局 display: flex; justify-content: center; align-items: center;
.son1 {
position: absolute;
width: 200px;
height: 200px;
background-color: red;
margin: auto;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
/* 利用定位+margin:负值 */
.son2 {
position: absolute;
top: 50%;
left: 50%;
margin-left: -50px;
margin-top: -50px;
width: 100px;
height: 100px;
background: red;
}
.son {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 100px;
height: 100px;
background: red;
}
/* display: flex;
justify-content: center;
align-items: center; */
.father {
display: flex;
justify-content: center;
align-items: center;
width: 200px;
height: 200px;
background: skyblue;
}