Skip to content
全部文档

justify-items ​

用于控制 grid 项目沿其行轴如何对齐的工具类。

快速参考 ​

类属性
justify-items-startjustify-items: start;
justify-items-endjustify-items: end;
justify-items-end-safejustify-items: safe end;
justify-items-centerjustify-items: center;
justify-items-center-safejustify-items: safe center;
justify-items-stretchjustify-items: stretch;
justify-items-normaljustify-items: normal;

示例 ​

起点 ​

使用 justify-items-start 工具类,将 grid 项目对齐到其行轴的起点:

01
02
03
04
05
06
html
<div class="grid justify-items-start ...">
  <div>01</div>
  <div>02</div>
  <div>03</div>
  <div>04</div>
  <div>05</div>
  <div>06</div>
</div>

终点 ​

使用 justify-items-end 或 justify-items-end-safe 工具类,将 grid 项目对齐到其行轴的终点:

justify-items-end

01
02
03

justify-items-end-safe

01
02
03
justify-items-end
html
<div class="grid grid-flow-col justify-items-end ...">
  <div>01</div>
  <div>02</div>
  <div>03</div>
</div>
justify-items-end-safe
html
<div class="grid grid-flow-col justify-items-end-safe ...">
  <div>01</div>
  <div>02</div>
  <div>03</div>
</div>

当可用空间不足时,justify-items-end-safe 工具类会将项目对齐到容器起点,而不是终点。

居中 ​

使用 justify-items-center 或 justify-items-center-safe 工具类,将 grid 项目沿其行轴居中对齐:

justify-items-center

01
02
03

justify-items-center-safe

01
02
03
justify-items-center
html
<div class="grid grid-flow-col justify-items-center ...">
  <div>01</div>
  <div>02</div>
  <div>03</div>
</div>
justify-items-center-safe
html
<div class="grid grid-flow-col justify-items-center-safe ...">
  <div>01</div>
  <div>02</div>
  <div>03</div>
</div>

当可用空间不足时,justify-items-center-safe 工具类会将项目对齐到容器起点,而不是居中。

拉伸 ​

使用 justify-items-stretch 工具类,沿行轴拉伸项目:

01
02
03
04
05
06
html
<div class="grid justify-items-stretch ...">
  <div>01</div>
  <div>02</div>
  <div>03</div>
  <div>04</div>
  <div>05</div>
  <div>06</div>
</div>

响应式设计 ​

使用 md: 等断点变体作为 justify-items 工具类的前缀,即可只在中等屏幕尺寸及以上生效:

html
<div class="grid justify-items-start md:justify-items-center ...">
 <!-- ... -->
</div>

在变体文档中了解有关使用变体的更多信息。

文档译文以 MIT 协议授权;原文版权归 Tailwind Labs。湘ICP备2026005453号-2