不设宽高垂直居中

第一种

.div{
    position: absolute;
    top: 50%;
    left: 50%;
    z-index: 3;
    transform: translate(-50%,-50%);
}

第二种:

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

第三种:

.div{

  display:absolute;
  left:50%;
  top:50%;
  margin-left:-width/2;//负向偏移宽度的一半,如果width不定,需要动态获取。
  margin-top:-height/2;//原理同上

}

原文地址:https://www.cnblogs.com/Byme/p/5807536.html