首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >3列布局1列,2行等间距

问3列布局1列,2行等间距
EN

Stack Overflow用户
提问于 2015-06-09 20:34:16
回答 1查看 99关注 0票数 0

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

见图:

​

​

我试着给每一列添加百分比,所以列之间有1%的填充,在列2的顶行大约有8.3%的边距底部,它看起来不是很准确也不可靠,有没有更好的从ie8+开始工作。谢谢!

EN

回答 1

Stack Overflow用户

发布于 2015-06-09 21:43:38

这个应该可以了。注释中的解释。

​

代码语言:javascript
复制
.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 */
}
代码语言:javascript
复制
<div class="container">
    <div></div>
    <div></div>
    <div></div>
    <div></div>
</div>

​

编辑:

这里有一个更简单的解决方案,它有更好的浏览器支持:

​

代码语言:javascript
复制
table{
    width:100%;
    height:300px;
    border-spacing: 10px;
    border-collapse: separate;
}

td{
    background-color:grey;
}
代码语言:javascript
复制
<table>
    <tr>
        <td rowspan="2"></td>
        <td></td>
        <td rowspan="2"></td>
    </tr>
    <tr>
        <td></td>
    </tr>
</table>

​

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30732185

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档