1. 弹性盒子与网格
  2. 自我放置

弹性盒子与网格

place-self

用于控制单个项目在同一时间如何被对齐和定位的工具类。

ClassStyles
place-self-auto
place-self: auto;
place-self-start
place-self: start;
place-self-end
place-self: end;
place-self-center
place-self: center;
place-self-stretch
place-self: stretch;

示例

自动

使用 place-self-auto 根据容器的 place-items 属性的值对齐项目:

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

开始

使用 place-self-start 将项目在两个轴上对齐到开始位置:

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

中心

使用 place-self-center 将项目在两个轴上对齐到中心位置:

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

结束

使用 place-self-end 将项目在两个轴上对齐到结束位置:

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

拉伸

使用 place-self-stretch 在两个轴上拉伸项目:

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

响应式设计

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

<div class="place-self-start md:place-self-end ...">
<!-- ... -->
</div>

Learn more about using variants in the variants documentation.