这里我只介绍使用margin实现水平居中的方法,不多说看代码!
html代码:
我们先创建一个div盒子:
<div class="box"></div>
然后用css实现盒子的居中
其实css实现居中的思路很简单,给盒子一个宽度,然后再设置盒子margin的左右值为“auto”,就可以实现div盒子的居中了
.box{
width:200px;
height:200px;
background:#333;
margin:0 auto;
}