1. 弹性盒子与网格
  2. 网格行

弹性盒子与网格

grid-row

用于控制元素在网格行中大小和位置的工具类。

ClassStyles
row-span-<number>
grid-row: span <number> / span <number>;
row-span-full
grid-row: 1 / -1;
row-span-(<custom-property>)
grid-row: span var(<custom-property>) / span var(<custom-property>);
row-span-[<value>]
grid-row: span <value> / span <value>;
row-start-<number>
grid-row-start: <number>;
-row-start-<number>
grid-row-start: calc(<number> * -1);
row-start-auto
grid-row-start: auto;
row-start-(<custom-property>)
grid-row-start: var(<custom-property>);
row-start-[<value>]
grid-row-start: <value>;
row-end-<number>
grid-row-end: <number>;

示例

跨行

使用 row-span-<number> 工具类,如 row-span-2row-span-4,使元素跨越 n 行:

01
02
03
<div class="grid grid-flow-col grid-rows-3 gap-4">
<div class="row-span-3 ...">01</div>
<div class="col-span-2 ...">02</div>
<div class="col-span-2 row-span-2 ...">03</div>
</div>

起始和结束线

使用 row-start-<number>row-end-<number> 工具类,如 row-start-2row-end-3,使元素在第 n 个网格线上开始或结束:

01
02
03
<div class="grid grid-flow-col grid-rows-3 gap-4">
<div class="row-span-2 row-start-2 ...">01</div>
<div class="row-span-2 row-end-3 ...">02</div>
<div class="row-start-1 row-end-4 ...">03</div>
</div>

这些也可以与 row-span-<number> 工具类结合使用,以跨越特定数量的行。

使用自定义值

Use utilities like row-[<value>],row-span-[<value>],row-start-[<value>], and row-end-[<value>] to set the 网格行大小和位置 based on a completely custom value:

<div class="row-[span_16_/_span_16] ...">
<!-- ... -->
</div>

For CSS variables, you can also use the row-(<custom-property>) syntax:

<div class="row-(--my-rows) ...">
<!-- ... -->
</div>

This is just a shorthand for row-[var(<custom-property>)] that adds the var() function for you automatically.

响应式设计

Prefix grid-row,grid-row-start, and grid-row-end utilities with a breakpoint variant like md: to only apply the utility at medium screen sizes and above:

<div class="row-span-3 md:row-span-4 ...">
<!-- ... -->
</div>

Learn more about using variants in the variants documentation.