css/css3实现未知宽高元素的垂直居中和水平居中

题目:
.a{
   200px;
  height: 200px;
  background-color: #ccc;
}

<body>  
  <div class="a">
    <div class="b">1111</div>
  </div>
</body>

1、第一种 css3的transform

  .a{

    position: relative;

  }

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

2、第二种 display的table-cell  

  .a{

    display: table;

  }  

  .b{
    display: table-cell;
    text-align: center;
    vertical-align: middle;

  }

 3、第三种  flex盒子布局

  .a{
    display: flex;

    justify-content: center;

    align-items: center;

  }

原文地址:https://www.cnblogs.com/luckyXcc/p/9127704.html