Skip to content
全部文档

justify-self

用于控制单个 grid 项目沿其行轴如何对齐的工具类。

快速参考

属性
justify-self-autojustify-self: auto;
justify-self-startjustify-self: start;
justify-self-centerjustify-self: center;
justify-self-center-safejustify-self: safe center;
justify-self-endjustify-self: end;
justify-self-end-safejustify-self: safe end;
justify-self-stretchjustify-self: stretch;

示例

Auto

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

01
02
03
04
05
06
html
<!-- [!code classes:justify-self-auto] -->
<div class="grid justify-items-stretch ...">
  <!-- ... -->
  <div class="justify-self-auto ...">02</div>
  <!-- ... -->
</div>

起点

使用 justify-self-start 工具类,将 grid 项目对齐到其行轴的起点:

01
02
03
04
05
06
html
<!-- [!code classes:justify-self-start] -->
<div class="grid justify-items-stretch ...">
  <!-- ... -->
  <div class="justify-self-start ...">02</div>
  <!-- ... -->
</div>

居中

使用 justify-self-centerjustify-self-center-safe 工具类,将 grid 项目沿其行轴居中对齐:

justify-self-center

01
02
03

justify-self-center-safe

01
02
03
justify-self-center
html
<!-- [!code classes:justify-self-center] -->
<div class="grid justify-items-stretch ...">
  <!-- ... -->
  <div class="justify-self-center ...">02</div>
  <!-- ... -->
</div>
justify-self-center-safe
html
<!-- [!code classes: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 工具类,将 grid 项目对齐到其行轴的终点:

justify-self-end

01
02
03

justify-self-end-safe

01
02
03
justify-self-end
html
<!-- [!code classes:justify-self-end] -->
<div class="grid justify-items-stretch ...">
  <!-- ... -->
  <div class="justify-self-end ...">02</div>
  <!-- ... -->
</div>
justify-self-end-safe
html
<!-- [!code classes: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 工具类,沿行轴拉伸 grid 项目以填满网格区域:

01
02
03
04
05
06
html
<!-- [!code classes:justify-self-stretch] -->
<div class="grid justify-items-start ...">
  <!-- ... -->
  <div class="justify-self-stretch ...">02</div>
  <!-- ... -->
</div>

响应式设计

使用 md: 等断点变体作为 justify-self 工具类的前缀,即可只在中等屏幕尺寸及以上生效:

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

变体文档中了解有关使用变体的更多信息。

文档译文以 MIT 协议授权;原文版权归 Tailwind Labs。湘ICP备2026005453号-2