css实现水平垂直居中的方式
1.绝对定位+ transform: translate(-50%, -50%);
.parent {
height: 500px;
position: relative;
}
.child {
position: absolute;
left: 50%;
top: 50%;
/* 相对于元素的自身宽高进行平移 */
transform: translate(-50%, -50%);
}
2.绝对定位+margin:auto
.parent {
原创
2022-03-02 09:20:27 ·
51 阅读 ·
0 评论