1. 弹性盒 & 网格
  2. 网格行开始/结束

Quick reference

属性
row-autogrid-row: auto;
row-span-1grid-row: span 1 / span 1;
row-span-2grid-row: span 2 / span 2;
row-span-3grid-row: span 3 / span 3;
row-span-4grid-row: span 4 / span 4;
row-span-5grid-row: span 5 / span 5;
row-span-6grid-row: span 6 / span 6;
row-span-7grid-row: span 7 / span 7;
row-span-8grid-row: span 8 / span 8;
row-span-9grid-row: span 9 / span 9;
row-span-10grid-row: span 10 / span 10;
row-span-11grid-row: span 11 / span 11;
row-span-12grid-row: span 12 / span 12;
row-span-fullgrid-row: 1 / -1;
row-start-1grid-row-start: 1;
row-start-2grid-row-start: 2;
row-start-3grid-row-start: 3;
row-start-4grid-row-start: 4;
row-start-5grid-row-start: 5;
row-start-6grid-row-start: 6;
row-start-7grid-row-start: 7;
row-start-8grid-row-start: 8;
row-start-9grid-row-start: 9;
row-start-10grid-row-start: 10;
row-start-11grid-row-start: 11;
row-start-12grid-row-start: 12;
row-start-13grid-row-start: 13;
row-start-autogrid-row-start: auto;
row-end-1grid-row-end: 1;
row-end-2grid-row-end: 2;
row-end-3grid-row-end: 3;
row-end-4grid-row-end: 4;
row-end-5grid-row-end: 5;
row-end-6grid-row-end: 6;
row-end-7grid-row-end: 7;
row-end-8grid-row-end: 8;
row-end-9grid-row-end: 9;
row-end-10grid-row-end: 10;
row-end-11grid-row-end: 11;
row-end-12grid-row-end: 12;
row-end-13grid-row-end: 13;
row-end-autogrid-row-end: auto;

基本用法(Basic usage)

跨行(Spanning rows)

使用 row-span-* 工具使一个元素跨越 n 行。

🌐 Use the row-span-* utilities to make an element span n rows.

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

起始行和结束行(Starting and ending lines)

使用 row-start-*row-end-* 工具使元素从第 n 条网格线开始或结束。它们也可以与 row-span-* 工具结合使用,以跨越特定数量的行。

🌐 Use the row-start-* and row-end-* utilities to make an element start or end at the nth grid line. These can also be combined with the row-span-* utilities to span a specific number of rows.

请注意,CSS 网格线从 1 开始,而不是从 0 开始,因此在三行网格中,高度占满整行的元素将从第 1 条线开始,到第 4 条线结束。

🌐 Note that CSS grid lines start at 1, not 0, so a full-height element in a 3-row grid would start at line 1 and end at line 4.

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

有条件申请

悬停、聚焦及其他状态

Tailwind 允许你使用变体修饰符在不同状态下有条件地应用工具类。例如,使用hover:row-span-4 仅在 hover 时应用 row-span-4 工具。

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

有关所有可用状态修饰符的完整列表,请查看悬停、聚焦、以及其他状态 文档。

断点和媒体查询

你还可以使用变体修饰符来定位媒体查询,例如响应式断点、暗黑模式、首选减少运动等。例如,使用 md:row-span-4 仅在中等屏幕尺寸及以上时应用 row-span-4 工具。

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

要了解更多信息,请查看有关 响应式设计暗黑模式、以及 其他媒体查询修饰符 的文档。


使用自定义值(Using custom values)

自定义主题(Customizing your theme)

默认情况下,Tailwind 提供了用于处理多达 6 行显式网格的 grid-row 工具类。你可以通过编辑你的 tailwind.config.js 文件中的 theme.gridRowtheme.extend.gridRowtheme.gridRowStarttheme.extend.gridRowStarttheme.gridRowEndtheme.extend.gridRowEnd 来自定义这些值。

🌐 By default, Tailwind includes grid-row utilities for working with grids with up to 6 explicit rows. You can customize these values by editing theme.gridRow, theme.extend.gridRow, theme.gridRowStart, theme.extend.gridRowStart, theme.gridRowEnd, and theme.extend.gridRowEnd in your tailwind.config.js file.

要添加新的 row-* 工具,请自定义 Tailwind 主题配置中的 gridRow 部分:

🌐 To add new row-* utilities, customize the gridRow section of your Tailwind theme config:

tailwind.config.js
module.exports = {
  theme: {
    extend: {
      gridRow: {
        'span-16': 'span 16 / span 16',
      }
    }
  }
}

我们在内部将其用于我们的 row-span-* 工具。请注意,由于这是直接配置 grid-row 简写属性,我们在值名称中直接包含了 span 这个词,它不会自动内置到类名中。这意味着你可以自由添加任何你想要的条目——它们不必只是 span 工具。

🌐 We use this internally for our row-span-* utilities. Note that since this configures the grid-row shorthand property directly, we include the word span directly in the value name, it’s not baked into the class name automatically. That means you are free to add entries that do whatever you want here — they don’t just have to be span utilities.

要添加新的 row-start-* 工具,请自定义 Tailwind 主题配置中的 gridRowStart 部分:

🌐 To add new row-start-* utilities, customize the gridRowStart section of your Tailwind theme config:

tailwind.config.js
module.exports = {
  theme: {
    extend: {
      gridRowStart: {
        '8': '8',
        '9': '9',
        '10': '10',
        '11': '11',
        '12': '12',
        '13': '13',
      }
    }
  }
}

要添加新的 row-end-* 工具,请自定义 Tailwind 主题配置中的 gridRowEnd 部分:

🌐 To add new row-end-* utilities, customize the gridRowEnd section of your Tailwind theme config:

tailwind.config.js
module.exports = {
  theme: {
    extend: {
      gridRowEnd: {
        '8': '8',
        '9': '9',
        '10': '10',
        '11': '11',
        '12': '12',
        '13': '13',
      }
    }
  }
}

主题自定义文档中了解有关自定义默认主题的更多信息。

🌐 Learn more about customizing the default theme in the theme customization documentation.

任意值(Arbitrary values)

如果你需要使用一次性的 grid row 值,而该值没有必要包含在你的主题中,请使用方括号动态生成属性,使用任意值。

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

任意值 文档中了解有关任意值支持的更多信息。