【发布时间】:2015-05-14 05:19:54
【问题描述】:
我想仅使用 CSS 而不是 jquery 或 javascript 创建此布局。是否可能,如果可以,请指导我找到正确的来源。谢谢你:)
我试过了,但效果不佳: http://codepen.io/anon/pen/GJZWoX
HTML:
<div class="parent">
<div class="red">
</div>
<div class="blue">
</div>
<div class="red">
</div>
<div class="red">
</div>
</div>
CSS:
.parent{
width:330px;
}
.red{
float:left;
width:150px;
height:150px;
margin-bottom:10px;
margin-left:10px;
background-color:red;
}
.blue{
float:left;
width:150px;
height:300px;
margin-bottom:10px;
margin-left:10px;
background-color:blue;
}
【问题讨论】:
-
使用
column-count和column-gap -
你不只需要设置
height: auto并插入内容吗? div 的高度会根据内容的大小自动改变它的高度。基本上,您所要做的就是设置每列的列数和宽度。