获得徽章 0
- 让盒子垂直水平居中的三种方法:
1:定位,子绝父相
.father {
position: relative;
}
.son {
position: absolute;
top: 50%;
left: 50%;
margin-top: -50px;
margin-left: -50px;
}
2:flex布局(最常用)
.father {
display: flex;
justify-content: center;
align-items: center;
}
.son {
}
3:transform
.father {
position: relative;
}
.son {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}展开23
![[看]](http://lf-web-assets.juejin.cn/obj/juejin-web/xitu_juejin_web/img/jj_emoji_97.39cdc9f.png)