创建div
然后是css中这样写
.parent {
position: relative;
width: 500px;
height: 500px;
border: 1px solid red;
}
.child {
position: absolute;
width: 250px;
height: 250px;
left: 50%;
top: 50%;
margin-left: -125px;
/*设置为宽度(width:250px;)的一半*/
margin-top: -125px;
/*设置为高度(height:250px;)的一半*/
background: #000;
}
html中让一个DIV在另一个DIV中水平垂直居中