2017-10-19 24 views
2

长方形格箱我已经安排在2×2格这四个div标签(中间一个只为换行)如何安排无间隙

<div class="rectangle"></div> 
<div class="rectangle"></div> 

<div class=""></div> 

<div class="rectangle"></div> 
<div class="rectangle"></div> 

随着这个CSS:

.rectangle { 
    width: 25px; 
    height: 25px; 
    background: #ccc; 
    display: inline-block; 
    margin: 0px; /* doesn't work */ 
    padding: 0px; /* doesn't work */ 
} 

的jsfiddle结果输出显示矩形之间的间隙。有没有办法摆脱差距?

http://jsfiddle.net/brMPs/958/

+0

https://www.google.com/search?q=inline-block+space+between,https://开头www.google.com/search?q=inline-block+space+under - 您做了什么研究? – CBroe

回答

2

你既可以漂浮留下的矩形或零出字体大小DIV标签之间的隐秘空间。在这里,试试这个添加div容器和使用

.container { 
    font-size: 0; 
} 

http://jsfiddle.net/brMPs/963/

0

你的空间是因为,你具备的要素(换行和一些标签算作之间的空间的原因空间,只是要清楚)。最小化的HTML会解决这个问题,还是这些招数之一:

<div class="rectangle"></div><div 
class="rectangle"> 
</div> 

<div class=""></div> 

<div class="rectangle"></div><div 
class="rectangle"> 
</div> 

https://css-tricks.com/fighting-the-space-between-inline-block-elements/

+0

也jsfiddle http://jsfiddle.net/brMPs/964/ –