1. 弹性和网格
  2. 自我证明

Quick reference

Class
Properties
justify-self-autojustify-self: auto;
justify-self-startjustify-self: start;
justify-self-endjustify-self: end;
justify-self-centerjustify-self: center;
justify-self-stretchjustify-self: stretch;

基础用法

自动

使用 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>

Start

使用 justify-self-start 将网格项与其内联轴的起点对齐:

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

Center

使用 justify-self-center 将网格项沿其内联轴的中心对齐:

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

End

使用 justify-self-end 将网格项与其内联轴的末尾对齐:

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

Stretch

使用 justify-self-stretch 拉伸网格项以填充其内联轴上的网格区域:

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

条件应用

悬停、聚焦和其他状态

Tailwind 允许您使用变体修饰符有条件地在不同状态下应用实用程序类。例如,使用 hover:justify-self-end 来仅 在 hover应用 justify-self-end.

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

详细了解, 请参考 Hover, Focus, & Other States 文档.

断点和媒体查询

您还可以使用变体修饰符来定位媒体查询,例如响应式断点、暗模式、首选减少运动等。例如, 使用 md:justify-self-end 来应用 justify-self-end 程序,适用于中等屏幕尺寸及以上。

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

进一步了解,请参考 响应式设计, 暗黑模式 媒体查询.