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

Quick reference

Class
Properties
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 lets you conditionally apply utility classes in different states using variant modifiers. For example, use hover:items-center to only apply the items-center utility on hover.

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

For a complete list of all available state modifiers, check out the Hover, Focus, & Other States documentation.

断点和媒体查询

You can also use variant modifiers to target media queries like responsive breakpoints, dark mode, prefers-reduced-motion, and more. For example, use md:items-center to apply the items-center utility at only medium screen sizes and above.

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

To learn more, check out the documentation on Responsive Design, Dark Mode and other media query modifiers.