<style type="text/css">
.box{
height: 200px;
width: 200px;
border: 1px red solid;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
}
</style>
<div class="box"></div>
这里我给div设置了绝对定位(position: absolute;),然后给上下左右(top,bottom,left,right)4个属性设置为0,再用外边距居中(margin: auto;),从而达到div居中的效果,这样就好了