我试图在CSS中实现这种响应式的流畅布局,这样每列都有相同的高度和宽度,中间的列有2行,列和行之间的间距应该相同,当调整大小时,间距应该保持相等的距离。每个块都是一个图像。
见图:

我试着给每一列添加百分比,所以列之间有1%的填充,在列2的顶行大约有8.3%的边距底部,它看起来不是很准确也不可靠,有没有更好的从ie8+开始工作。谢谢!
发布于 2015-06-09 21:43:38
这个应该可以了。注释中的解释。
.container {
width:100%;
height:500px;
-webkit-columns:auto 3;
-moz-columns:auto 3;
columns:auto 3;
-webkit-column-gap:10px;
-moz-column-gap:10px;
column-gap:10px;
box-shadow: 0 0 0 1px red; /* just to show container dimensions */
}
.container>div {
background-color:grey;
width:100%;
height:100%;
box-sizing:border-box; /* in case you plan on using padding */
}
.container>div:not(:nth-child(3n+1)) { /* second and third div from every set of 4 divs */
height:calc(50% - 5px); /* minus half of the space between the two smaller boxes */
}
.container>div:nth-child(4n+2) { /* second div from every set of 4 divs, if there's only going to be one set, you can use :nth-child(2) instead */
margin-bottom:10px; /* this should be the same as your column gap */
}<div class="container">
<div></div>
<div></div>
<div></div>
<div></div>
</div>
编辑:
这里有一个更简单的解决方案,它有更好的浏览器支持:
table{
width:100%;
height:300px;
border-spacing: 10px;
border-collapse: separate;
}
td{
background-color:grey;
}<table>
<tr>
<td rowspan="2"></td>
<td></td>
<td rowspan="2"></td>
</tr>
<tr>
<td></td>
</tr>
</table>
https://stackoverflow.com/questions/30732185
复制相似问题