方法一:
.wrap{
width:600px;
height:600px;
border:1px solid #000;
margin:30px auto;
position:relative;
}
.box{
width:300px;
height:300px;
background:red;
position:absolute;//一定要有的属性
left:0;
right:0;
top:0;
bottom:0;
margin:auto;
}
方法二:
.wrap{
width:600px;
height:600px;
border:1px solid #000;
margin:30px auto;
position:relative;
}
.box{
width:300px;
height:300px;
background:red;
position:absolute;//一定要有的属性
left:50%;
top:50%;
margin-left:-150px;
margin-top:-150px;
}
<div class="wrap">
<div class="box"><div>
</div>