HTML:
<div id="box">
<div id="chil-box"> test </div>
</div>
方式一:
#box {
width: 100px;
height: 100px;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
background-color: #F4F4F4;
}
方式二:
#box {
width: 100px;
height: 100px;
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
margin: auto;
background-color: #F4F4F4;
}
方式三:
#box {
width: 100px;
height: 100px;
position: absolute;
left: 50%;
top: 50%;
margin-left: -50px;
margin-top: -50px;
background-color: #F4F4F4;
}
方式四:
#box{
height:800px;
display:flex;
align-items:center;
justify-content:center;
-webkit-display:flex;
-webkit-align-items:center;
-webkit-justify-content:center;
}
#chil-box{
width:600px;
height:600px;
background-color: #F4F4F4;
}