1. 弹性盒 & 网格
  2. 网格自动行

Quick reference

属性
auto-rows-autogrid-auto-rows: auto;
auto-rows-mingrid-auto-rows: min-content;
auto-rows-maxgrid-auto-rows: max-content;
auto-rows-frgrid-auto-rows: minmax(0, 1fr);

基本用法(Basic usage)

调整隐式创建的网格行的大小(Sizing implicitly-created grid rows)

使用 auto-rows-* 工具来控制自动创建的网格行的大小。

🌐 Use the auto-rows-* utilities to control the size of implicitly-created grid rows.

<div class="grid grid-flow-row auto-rows-max">
  <div>01</div>
  <div>02</div>
  <div>03</div>
</div>

有条件申请

悬停、聚焦及其他状态

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

<div class="grid grid-flow-row auto-rows-max hover:auto-rows-min">
  <!-- ... -->
</div>

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

断点和媒体查询

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

<div class="grid grid-flow-row auto-rows-max md:auto-rows-min">
  <!-- ... -->
</div>

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


使用自定义值(Using custom values)

自定义主题(Customizing your theme)

默认情况下,Tailwind 包含四个通用的 grid-auto-rows 工具类。你可以通过编辑 tailwind.config.js 文件中的 theme.gridAutoRowstheme.extend.gridAutoRows 来自定义这些值。

🌐 By default, Tailwind includes four general purpose grid-auto-rows utilities. You can customize these values by editing theme.gridAutoRows or theme.extend.gridAutoRows in your tailwind.config.js file.

tailwind.config.js
module.exports = {
  theme: {
    extend: {
      gridAutoRows: {
        '2fr': 'minmax(0, 2fr)',
      }
    }
  }
}

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

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

任意值(Arbitrary values)

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

<div class="grid grid-flow-row auto-rows-[minmax(0,_2fr)]">
  <!-- ... -->
</div>

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