一、传统方法

<div class="wrap">
  <div class="inner">html : 让 inner 居中</div>
</div>
.wrap {
  float: left; /* 自适应内容宽度 */
  position: relative;
  left: 50%; 
}
.inner {
  position: relative;
  left: -50%; 
}

二、flex布局,水平垂直居中

<div class="wrap"></div>
.wrap {
  display: flex; 
  align-items: center;
  justify-content: center;
}

 

相关文章:

  • 2022-01-30
  • 2022-12-23
  • 2022-12-23
  • 2021-07-26
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-01-10
  • 2021-10-27
  • 2022-12-23
  • 2021-05-28
  • 2022-12-23
  • 2021-11-21
相关资源
相似解决方案