1. 弹性盒 & 网格
  2. 横向对齐条目

Quick reference

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

基本用法(Basic usage)

拉紧(Stretch)

使用 items-stretch 将项目拉伸以填充容器的交叉轴:

🌐 Use items-stretch to stretch items to fill the container’s cross axis:

01
02
03
<div class="flex items-stretch ...">
  <div class="py-4">01</div>
  <div class="py-12">02</div>
  <div class="py-8">03</div>
</div>

开始(Start)

使用 items-start 将项目对齐到容器交叉轴的起点:

🌐 Use items-start to align items to the start of the container’s cross axis:

01
02
03
<div class="flex items-start ...">
  <div class="py-4">01</div>
  <div class="py-12">02</div>
  <div class="py-8">03</div>
</div>

中心(Center)

使用 items-center 将项目沿容器的交叉轴居中对齐:

🌐 Use items-center to align items along the center of the container’s cross axis:

01
02
03
<div class="flex items-center ...">
  <div class="py-4">01</div>
  <div class="py-12">02</div>
  <div class="py-8">03</div>
</div>

结尾(End)

使用 items-end 将项目对齐到容器交叉轴的末端:

🌐 Use items-end to align items to the end of the container’s cross axis:

01
02
03
<div class="flex items-end ...">
  <div class="py-4">01</div>
  <div class="py-12">02</div>
  <div class="py-8">03</div>
</div>

基线(Baseline)

使用 items-baseline 沿容器的交叉轴对齐项目,以便它们的所有基线对齐:

🌐 Use items-baseline to align items along the container’s cross axis such that all of their baselines align:

01
02
03
<div class="flex items-baseline ...">
  <div class="pt-2 pb-6">01</div>
  <div class="pt-8 pb-12">02</div>
  <div class="pt-12 pb-4">03</div>
</div>

有条件申请

悬停、聚焦及其他状态

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

<div class="flex items-stretch hover:items-center">
  <!-- ... -->
</div>

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

断点和媒体查询

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

<div class="flex items-stretch md:items-center">
  <!-- ... -->
</div>

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