我的乖乖啥昵称

博客园 首页 联系 订阅 管理

绝对定位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种实现元素水平居中的方法)
posted on 2018-07-11 09:25  我的乖乖啥昵称  阅读(259)  评论(0编辑  收藏  举报