hfeng007

绝对定位absolute,left:50%,加上margin-left:-(宽度/2),可以实现绝对位置居中

.list{
width: 1200px;
height: 300px;
overflow: hidden;
position: absolute;
left: 50%;
margin-left: -600px;
}

上面是早期使用的绝对定位实现水平居中,但是缺点是,常常不知道元素的宽度是多少。
https://www.w3cplus.com/css/elements-horizontally-center-with-css.html(6种实现元素水平居中的方法)

分类:

技术点:

相关文章:

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