方法一 :使用css3的transform来实现
<div class="parent">
<div class="child">
<p></p>
</div>
</div>
.parent {
width: 100%;
height: 100%;
background-color: antiquewhite;
}
.child {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.child p {
width: 300px;
height: 400px;
background-color: rgb(78, 151, 211);
}
方法二:flex 布局
<div class="parent">
<div class="child"></div>
</div>
.parent{
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height:100%;
background-color: antiquewhite;
}
.parent .child{
width: 200px;
height: 300px;
background-color: rgb(78, 151, 211);
}
![E3,size_16,color_FFFFFF,t_70)](https://img-blog.csdnimg.cn/777e744e49404dd19417b144c1c5d5af.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQyNjA3NTE3,size_16,color_FFFFFF,t_70)