我正在使用CSS列布局模块创建流式布局,但是在同一列的两个或更多元素之间会出现意外的结果。元素之间会出现3到4像素的间隙。我已经在IE11、FireFox 24、Chrome 31和Safari 5.1.7中进行了测试,它们都表现出相同的行为。
<div class="tile-container">
<div class="tile-large">1</div>
<div class="tile-wide">2</div>
<div class="tile-small">3</div>
<div class="tile-small">4</div>
<div class="tile-small">5</div>
<div class="tile-small">6</div>
<div class="tile-wide">7</div>
<div class="tile-large">8</div>
</div>
.tile-container {
-moz-column-width: 250px;
-webkit-column-width: 250px;
column-width: 250px;
column-fill: auto;
height: 502px;
background-color: gray;
}
.tile-large {
width: 250px;
height: 250px;
-webkit-column-break-inside: avoid;
break-inside: avoid;
display: inline-block;
background-color: green;
}
.tile-wide {
width: 250px;
height: 125px;
-webkit-column-break-inside: avoid;
break-inside: avoid;
display: inline-block;
background-color: blue;
}
.tile-small {
width: 125px;
height: 125px;
-webkit-column-break-inside: avoid;
break-inside: avoid;
display: inline-block;
background-color: red;
}
我不想使用负边距来关闭间隙,因为我想引入拖放行为。左浮动将消除间隙,但这会引入另一组问题。有趣的是,当我使用jQueryUI sortable时,在拖放事件之后,jQueryUI排列元素后,间隙不再存在。