1. Flexbox 和 Grid
  2. align-self

Flexbox 和 Grid

align-self

Utilities for controlling how an individual flex or grid item is positioned along its container's cross axis.

样式
self-auto
align-self: auto;
self-start
align-self: flex-start;
self-end
align-self: flex-end;
self-center
align-self: center;
self-stretch
align-self: stretch;
self-baseline
align-self: baseline;

示例(Examples)

¥Examples

自动(Auto)

¥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)

¥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)

¥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)

¥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)

¥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>

响应式设计(Responsive design)

¥Responsive design

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

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

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

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