1. 弹性盒子与网格
  2. 网格自动排列

弹性盒子与网格

grid-auto-flow

用于控制网格中元素自动放置的工具。

ClassStyles
grid-flow-row
grid-auto-flow: row;
grid-flow-col
grid-auto-flow: column;
grid-flow-dense
grid-auto-flow: dense;
grid-flow-row-dense
grid-auto-flow: row dense;
grid-flow-col-dense
grid-auto-flow: column dense;

示例

基本示例

使用 grid-flow-colgrid-flow-row-dense 等工具来控制自动放置算法在网格布局中的工作方式:

01
02
03
04
05
<div class="grid grid-flow-row-dense grid-cols-3 grid-rows-3 ...">
<div class="col-span-2">01</div>
<div class="col-span-2">02</div>
<div>03</div>
<div>04</div>
<div>05</div>
</div>

响应式设计

Prefix a grid-auto-flow utility with a breakpoint variant like md: to only apply the utility at medium screen sizes and above:

<div class="grid grid-flow-col md:grid-flow-row ...">
<!-- ... -->
</div>

Learn more about using variants in the variants documentation.