水平垂直居中

/* 弹性布局 */

.parent{
    display: -webkit-flex;
    justify-content: center;
    align-items: center;
}

/* 定位 + margin */

.parent{
    position: relative;
}
.child{
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    margin: auto;
}

/* 定位 + transform */

.child{
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
}

/* 定位 + margin负值 */

.child{
    position: absolute;
    left: 50%;
    top: 50%;
    margin-top: -50px; /* 子盒子高度的一半 */
    margin-left: -50px; /* 子盒子宽度的一半 */
}

  

原文地址:https://www.cnblogs.com/handsome-jm/p/7380603.html