css实现块级元素的水平居中的2种常用方法

第一种:

利用margin来水平居中

.bl{
margin: 0 auto;
background: red;
100px;
height: 100px;
}

  

第二种:利用百分比,利用50%,然后减去自己的一半.

.bl2{
position: relative;
left: 50%;
200px;
height: 200px;
background: green;
margin-left: -100px;
}

  

  

原文地址:https://www.cnblogs.com/biyongyao/p/7301917.html