1.使用flex实现,box为父容器,tes为子容器
#box{
display: flex;
height: 700px;
width: 700px;
background-color: brown;
justify-content: center;
align-items: center;
border: 1px solid red;
}
#tes{
width:200px;
height: 200px;
border: 1px solid red;
background-color: aqua;
}
2.不使用flex,box为父容器,tes为子容器
#box{
height: 700px;
width: 700px;
background-color: brown;
border: 1px solid red;
position: relative;
}
#tes{
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: auto;
border: 1px solid red;
width: 100px;
height: 100px;
position: absolute;
}
#box{
height: 700px;
width: 700px;
border: 1px solid red;
position: relative;
}
#tes2{
width: 100px;
height: 100px;
border: 1px solid red;
background-color: aqua;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
position: absolute;
}