1. Flexbox 和 Grid
  2. align-items

Flexbox 和 Grid

align-items

Utilities for controlling how flex and grid items are positioned along a container's cross axis.

样式
items-start
align-items: flex-start;
items-end
align-items: flex-end;
items-end-safe
align-items: safe flex-end;
items-center
align-items: center;
items-center-safe
align-items: safe center;
items-baseline
align-items: baseline;
items-baseline-last
align-items: last baseline;
items-stretch
align-items: stretch;

示例(Examples)

¥Examples

拉紧(Stretch)

¥Stretch

使用 items-stretch 工具拉伸网格项以填充容器的横轴:

¥Use the items-stretch utility 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)

¥Start

使用 items-start 工具将项目与容器横轴的起点对齐:

¥Use the items-start utility 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)

¥Center

使用 items-center 工具将项目沿容器横轴的中心对齐:

¥Use the items-center utility 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)

¥End

使用 items-end 工具将项目与容器横轴的末端对齐:

¥Use the items-end utility 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)

¥Baseline

使用 items-baseline 工具沿容器的横轴对齐项目,使其所有基线都对齐:

¥Use the items-baseline utility 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>

最后基线(Last baseline)

¥Last baseline

使用 items-baseline-last 工具沿容器的横轴对齐项目,使其所有基线都与容器中的最后一条基线对齐:

¥Use the items-baseline-last utility to align items along the container's cross axis such that all of their baselines align with the last baseline in the container:

Spencer Sharp

Working on the future of astronaut recruitment at Space Recruit.

spacerecruit.com
Alex Reed

A multidisciplinary designer.

alex-reed.com
<div class="grid grid-cols-[1fr_auto] items-baseline-last">
<div>
<img src="img/spencer-sharp.jpg" />
<h4>Spencer Sharp</h4>
<p>Working on the future of astronaut recruitment at Space Recruit.</p>
</div>
<p>spacerecruit.com</p>
</div>

这对于确保文本项彼此对齐非常有用,即使它们的高度不同。

¥This is useful for ensuring that text items align with each other, even if they have different heights.

响应式设计(Responsive design)

¥Responsive design

align-items 工具前面使用断点变体如 md: 仅在 medium 屏幕尺寸及以上时应用工具:

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

请参阅 变体文档 详细了解如何使用变体。

TailwindCSS v4.1 中文网 - 粤ICP备13048890号