weixin_慕设计12341
2019-11-05 17:33
老师可以补充一下在不知道父子元素宽高的情况下实现水平垂直居中的方法吗
.parent{
width:500px;
height:500px;
position:relative;
}
.child{
width:100px;
height:100px;
position:absolute;
left:0;
right:0;
top:0;
bottom:0;
margin:auto;
}
flex布局
.parent {
display: flex;
justify-content: center;
align-items:center;
}
不知道宽高的情况下,就使用absolute + transform方案就可以,这种方案在项目中使用非常普遍
一课全面掌握主流CSS布局
5276 学习 · 60 问题
相似问题