1. 弹性盒 & 网格
  2. 横向对齐自身

Quick reference

属性
self-autoalign-self: auto;
self-startalign-self: flex-start;
self-endalign-self: flex-end;
self-centeralign-self: center;
self-stretchalign-self: stretch;
self-baselinealign-self: baseline;

基本用法(Basic usage)

自动(Auto)

使用 self-auto 根据容器的 align-items 属性值来对齐元素:

🌐 Use self-auto to align an item based on the value of the container’s align-items property:

01
02
03
<div class="flex items-stretch ...">
  <div>01</div>
  <div class="self-auto ...">02</div>
  <div>03</div>
</div>

开始(Start)

使用 self-start 将项目对齐到容器交叉轴的起始位置,即使容器的 align-items 值为某些其他值:

🌐 Use self-start to align an item to the start of the container’s cross axis, despite the container’s align-items value:

01
02
03
<div class="flex items-stretch ...">
  <div>01</div>
  <div class="self-start ...">02</div>
  <div>03</div>
</div>

中心(Center)

使用 self-center 可以将项目沿容器横轴的中心对齐,即使容器的 align-items 值不同:

🌐 Use self-center to align an item along the center of the container’s cross axis, despite the container’s align-items value:

01
02
03
<div class="flex items-stretch ...">
  <div>01</div>
  <div class="self-center ...">02</div>
  <div>03</div>
</div>

结尾(End)

使用 self-end 将项目对齐到容器交叉轴的末端,即使容器的 align-items 值为:

🌐 Use self-end to align an item to the end of the container’s cross axis, despite the container’s align-items value:

01
02
03
<div class="flex items-stretch ...">
  <div>01</div>
  <div class="self-end ...">02</div>
  <div>03</div>
</div>

拉紧(Stretch)

使用 self-stretch 将项目拉伸以填充容器的交叉轴,即使容器的 align-items 值为:

🌐 Use self-stretch to stretch an item to fill the container’s cross axis, despite the container’s align-items value:

01
02
03
<div class="flex items-stretch ...">
  <div>01</div>
  <div class="self-stretch ...">02</div>
  <div>03</div>
</div>

有条件申请

悬停、聚焦及其他状态

Tailwind 允许你使用变体修饰符在不同状态下有条件地应用工具类。例如,使用hover:self-end 仅在 hover 时应用 self-end 工具。

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

有关所有可用状态修饰符的完整列表,请查看悬停、聚焦、以及其他状态 文档。

断点和媒体查询

你还可以使用变体修饰符来定位媒体查询,例如响应式断点、暗黑模式、首选减少运动等。例如,使用 md:self-end 仅在中等屏幕尺寸及以上时应用 self-end 工具。

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

要了解更多信息,请查看有关 响应式设计暗黑模式、以及 其他媒体查询修饰符 的文档。