【发布时间】:2015-09-16 13:52:47
【问题描述】:
我有 9 个 div 的容器,我想按以下方式排列元素:
它看起来像这样:
_________ ____ ____
| A | B | C |
| |____|____|
| | D | E |
|_________|____|____|
| F | G | H | I |
|____|____|____|____|
其中所有元素将始终为正方形(宽度 = 高度),我将确定它们在容器外的百分比大小。 在上面的示例中,例如 A 尺寸(宽度和高度)= 宽度的 50%,B 尺寸 = 25%。我还想在每个元素之间留出大约 5px 的边距。
我的尝试如下
<div id="grid">
<div class="block big">
</div>
<div class="block small">
</div>
<div class="block small">
</div>
<div class="block small">
</div>
<div class="block small">
</div>
<div class="block small">
</div>
<div class="block small">
</div>
<div class="block small">
</div>
<div class="block small">
</div>
</div>
和css:
#grid {width: 90%; position: relative}
.block {margin: 5px; background-size: cover; position: relative; display: inline-block}
.big {width: 50%; height: 0; padding-bottom: 50%; background-color: #eee}
.small {width: 25%; height: 0; padding-bottom: 25%; background-color: #eee}
【问题讨论】: