我有以下div。假设每个 div 向左浮动或将 display 设置为 inline-block。
+-----------+ +-----------+ +--------------+
| 1 | | 2 | | |
+-----------+ | | | 3 |
+-----------+ | |
+--------------+
+-----------+ +-----------+ +--------------+
| 4 | | 5 | | |
+-----------+ | | | 6 |
+-----------+ | |
+--------------+
+-----------+ +-----------+ +--------------+
| | | 8 | | 9 |
| 7 | +-----------+ | |
| | +--------------+
| |
+-----------+
我想实现这样
+-------------+ +-----------+ +-------------+
| 1 | | 4 | | |
+-------------+ +-----------+ | 7 |
+-------------+ +-----------+ | |
| 2 | | 5 | | |
| | | | +-------------+
+-------------+ +-----------+ +-------------+
+-------------+ +-----------+ | 8 |
| | | | +-------------+
| 3 | | 6 + +-------------+
| | | | | 9 |
| | +-----------+ | |
+-------------+ +-------------+
我知道我可以按列做到这一点
<div class="col1">
<div></div>
<div></div>
<div></div>
</div>
<div class="col2">
<div></div>
<div></div>
<div></div>
</div>
<div class="col3">
<div></div>
<div></div>
<div></div>
</div>
但是在我的网站上有更多这样的页面,所以我想在不触及标记的情况下实现。有什么想法可以使用 css 或任何 javascript/jquery 方法执行此操作吗?