<div class="outer">
<div class="inner"></div>
</div>
第一种方法
.outer{
height: 500px;
width: 500px;
border: solid 1px #000;
position: relative;
}
.inner{
width: 100px;
height: 100px;
background-color: red;
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
margin: auto;
}
第二种方法
.outer{
height: 500px;
width: 500px;
border: solid 1px #000;
position: relative;
}
.inner{
width: 100px;
height: 100px;
position: absolute;
top: 50%;
left: 50%;
margin-top: -50px;
margin-left: -50px;
background-color: red;
}