inline-block布局消除盒子中间的空隙

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_41033913/article/details/88045493

在使用inline-block对元素进行布局的时候,发现会有空隙出现

<div style="background-color: blue">
		<div style="display: inline-block; background-color: red; height: 200px;width: 200px"></div>
		<div style="display: inline-block; background-color: red; height: 200px;width: 200px"></div>
</div>

其实如果按照正常写文字的理解就是,就相当于文字与文字之间的一种空隙

那么去除间隙的两种方法:

①把大盒子(父元素)的font-size:0即可,大的盒子没有了文字的大小,那么之间的间隙自然而然的没有了

②其实为什么有间隙的真正原因是在写代码的时候追求代码的规范,第一个div与第二个div之间在html中就有间隙,如果把间隙去掉那么小盒子之间的间隙自然而然的就会消失,但是这样不符合代码规范,所以选择第一种方法比较推荐

猜你喜欢

转载自blog.csdn.net/qq_41033913/article/details/88045493