1. 弹性盒子与网格
  2. 项目放置

弹性盒子与网格

place-items

用于控制项目如何同时进行对齐和排列的实用程序。

ClassStyles
place-items-start
place-items: start;
place-items-end
place-items: end;
place-items-center
place-items: center;
place-items-baseline
place-items: baseline;
place-items-stretch
place-items: stretch;

示例

开始

使用 place-items-start 将网格项目放置在其网格区域的起始位置(两个轴):

01
02
03
04
05
06
<div class="grid grid-cols-3 place-items-start gap-4 ...">
<div>01</div>
<div>02</div>
<div>03</div>
<div>04</div>
<div>05</div>
<div>06</div>
</div>

结束

使用 place-items-end 将网格项目放置在其网格区域的结束位置(两个轴):

01
02
03
04
05
06
<div class="grid h-56 grid-cols-3 place-items-end gap-4 ...">
<div>01</div>
<div>02</div>
<div>03</div>
<div>04</div>
<div>05</div>
<div>06</div>
</div>

中心

使用 place-items-center 将网格项目放置在其网格区域的中央(两个轴):

01
02
03
04
05
06
<div class="grid h-56 grid-cols-3 place-items-center gap-4 ...">
<div>01</div>
<div>02</div>
<div>03</div>
<div>04</div>
<div>05</div>
<div>06</div>
</div>

拉伸

使用 place-items-stretch 按两个轴拉伸网格区域内的项目:

01
02
03
04
05
06
<div class="grid h-56 grid-cols-3 place-items-stretch gap-4 ...">
<div>01</div>
<div>02</div>
<div>03</div>
<div>04</div>
<div>05</div>
<div>06</div>
</div>

响应式设计

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

<div class="grid place-items-start md:place-items-center ...">
<!-- ... -->
</div>

Learn more about using variants in the variants documentation.