1. 弹性盒子与网格
  2. 项目对齐

弹性盒子与网格

align-items

控制 flex 和 grid 项在容器交叉轴上定位的工具类。

ClassStyles
items-start
align-items: flex-start;
items-end
align-items: flex-end;
items-center
align-items: center;
items-baseline
align-items: baseline;
items-stretch
align-items: stretch;

示例

拉伸

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

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>

开始

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

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>

居中

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

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>

结束

使用 items-end 将项目对齐到容器的交叉轴的结束位置:

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>

基线

使用 items-baseline 将项目沿容器的交叉轴对齐,使它们的基线保持一致:

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>

响应式设计

Prefix an align-items utility with a breakpoint variant like md: to only apply the utility at medium screen sizes and above:

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

Learn more about using variants in the variants documentation.