<div class="father">
<div class="son"></div>
</div>
一:
.father{
width:400px;
height:400px;
border:1px solid red;
position:relative;
}
.son{
width:100px;
height:100px;
background-color:pink;
border:1px solid red;
position:absolute;
left:50%;
top:50%;
/*margin-left:-50px;
margin-top:-50px;*/
transform: translate(-50%,-50%);
}
二:
.father{
width:400px;
height:400px;
border:1px solid red;
display:flex;
justify-content:center;
align-items:center;
}
.son{
width:100px;
height:100px;
background-color:pink;
border:1px solid red;
}