<div class="parent">
    <div class="item">居中</div>
</div>

方式一:使用transform

.item {
    position: relative;
    top: 50%;
    left: 50%;
    -webkit-transform: translate(-50%, -50%);
}

方式二:使用flex

.parent {
    display: -webkit-flex;
    justify-content: center; // 子元素水平居中
    align-items: center; // 子元素垂直居中
}

相关文章:

  • 2021-06-22
  • 2021-12-26
  • 2021-12-31
  • 2021-08-29
  • 2021-12-17
  • 2021-12-31
  • 2021-11-30
猜你喜欢
  • 2022-12-23
  • 2021-07-09
  • 2022-12-23
  • 2021-07-20
  • 2021-06-09
  • 2021-12-13
  • 2022-12-23
相关资源
相似解决方案