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

<body>  
  <div class="a">
    <div class="b">1111</div>
  </div>
</body>
 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;

  }

 

相关文章:

  • 2022-12-23
  • 2021-12-31
  • 2022-01-14
  • 2021-08-31
  • 2022-12-23
  • 2022-02-08
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-05
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案