1、常用flex布局
dispaly:flex;
justify-content: center; /* 垂直方向居中 */
align-items: center; /* 水平方向居中 */
2、绝对定位
.parent{
position:relative
}
.child{
position: absolute;
top: 50%;
left: 50%;
margin-left: -自身盒子一半;
margin-top: -自身盒子一半;
}
// 知道child高度
.child{
position: absolute;
top: 50%;
left: 50%;
margin-left: -自身盒子一半;
margin-top: -自身盒子一半;
}
// 不知道child高度
.child{
position: absolute;
margin: auto;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
.child{
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
}