解答
一道经典的问题,实现方法有很多种,以下是其中一种实现:
HTML结构:
<div class="wrapper">
<div class="content"></div>
</div>
CSS:
.wrapper{position:relative;}
.content{
background-color:#6699FF;
width:200px;
height:200px;
position: absolute; //父元素需要相对定位
top: 50%;
left: 50%;
margin-top:-100px ; //二分之一的height,width
margin-left: -100px;
}
清晰直白,真不戳