1. 弹性盒与网格
  2. justify-self(自对齐)

弹性盒与网格

justify-self

用于控制单个网格项目沿其行内轴对齐方式的工具类。

ClassStyles
justify-self-auto
justify-self: auto;
justify-self-start
justify-self: start;
justify-self-center
justify-self: center;
justify-self-center-safe
justify-self: safe center;
justify-self-end
justify-self: end;
justify-self-end-safe
justify-self: safe end;
justify-self-stretch
justify-self: stretch;

示例

Auto

使用 justify-self-auto 工具类根据网格容器的 justify-items 属性值来对齐项目:

01
02
03
04
05
06
<div class="grid justify-items-stretch ...">  <!-- ... -->  <div class="justify-self-auto ...">02</div>  <!-- ... --></div>

起始对齐

使用 justify-self-start 工具类将网格项沿其行内轴起始位置对齐:

01
02
03
04
05
06
<div class="grid justify-items-stretch ...">  <!-- ... -->  <div class="justify-self-start ...">02</div>  <!-- ... --></div>

居中

使用 justify-self-centerjustify-self-center-safe 工具类将网格项目沿其行内轴居中:

调整容器大小以查看对齐行为

justify-self-center

01
02
03

justify-self-center-safe

01
02
03
justify-self-center
<div class="grid justify-items-stretch ...">  <!-- ... -->  <div class="justify-self-center ...">02</div>  <!-- ... --></div>
justify-self-center-safe
<div class="grid justify-items-stretch ...">  <!-- ... -->  <div class="justify-self-center-safe ...">02</div>  <!-- ... --></div>

当可用空间不足时,justify-self-center-safe 工具类会将项目对齐到容器起始位置而非结束位置。

末端对齐

使用 justify-self-endjustify-self-end-safe 工具类将网格项沿其行内轴末端对齐:

调整容器大小以查看对齐行为

justify-self-end

01
02
03

justify-self-end-safe

01
02
03
justify-self-end
<div class="grid justify-items-stretch ...">  <!-- ... -->  <div class="justify-self-end ...">02</div>  <!-- ... --></div>
justify-self-end-safe
<div class="grid justify-items-stretch ...">  <!-- ... -->  <div class="justify-self-end-safe ...">02</div>  <!-- ... --></div>

当可用空间不足时,justify-self-end-safe 工具类会将项目对齐到容器起始端而非末端。

拉伸

使用 justify-self-stretch 工具类将网格项拉伸以填充其行轴上的网格区域:

01
02
03
04
05
06
<div class="grid justify-items-start ...">  <!-- ... -->  <div class="justify-self-stretch ...">02</div>  <!-- ... --></div>

响应式设计

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

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

Learn more about using variants in the variants documentation.

Copyright © 2025 Tailwind Labs Inc.·Trademark Policy