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

Quick reference

Class
Properties
grid-flow-rowgrid-auto-flow: row;
grid-flow-colgrid-auto-flow: column;
grid-flow-densegrid-auto-flow: dense;
grid-flow-row-densegrid-auto-flow: row dense;
grid-flow-col-densegrid-auto-flow: column dense;

基本用法

¥Basic usage

控制网格元素放置

¥Controlling grid element placement

使用 grid-flow-* 工具来控制自动放置算法如何适用于网格布局。

¥Use the grid-flow-* utilities to control how the auto-placement algorithm works for a grid layout.

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>

有条件地应用

悬停、聚焦和其他状态

Tailwind lets you conditionally apply utility classes in different states using variant modifiers. For example, use hover:grid-flow-row to only apply the grid-flow-row utility on hover.

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

For a complete list of all available state modifiers, check out the Hover, Focus, & Other States documentation.

断点和媒体查询

You can also use variant modifiers to target media queries like responsive breakpoints, dark mode, prefers-reduced-motion, and more. For example, use md:grid-flow-row to apply the grid-flow-row utility at only medium screen sizes and above.

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

To learn more, check out the documentation on Responsive Design, Dark Mode and other media query modifiers.