1. 弹性盒与网格
  2. justify-content(主轴对齐)

弹性盒与网格

justify-content

用于控制 flex 和 grid 项目沿容器主轴方向排列方式的工具类。

ClassStyles
justify-start
justify-content: flex-start;
justify-end
justify-content: flex-end;
justify-end-safe
justify-content: safe flex-end;
justify-center
justify-content: center;
justify-center-safe
justify-content: safe center;
justify-between
justify-content: space-between;
justify-around
justify-content: space-around;
justify-evenly
justify-content: space-evenly;
justify-stretch
justify-content: stretch;
justify-baseline
justify-content: baseline;
justify-normal
justify-content: normal;

示例

起始对齐

使用 justify-start 工具类将项目沿容器主轴起始端对齐:

01
02
03
<div class="flex justify-start ...">  <div>01</div>  <div>02</div>  <div>03</div></div>

居中

使用 justify-centerjustify-center-safe 工具类将项目沿容器主轴居中排列:

调整容器大小以查看对齐行为

justify-center

01
02
03
04

justify-center-safe

01
02
03
04
justify-center
<div class="flex justify-center ...">  <div>01</div>  <div>02</div>  <div>03</div>  <div>04</div></div>
justify-center-safe
<div class="flex justify-center-safe ...">  <div>01</div>  <div>02</div>  <div>03</div>  <div>04</div></div>

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

末端对齐

使用 justify-endjustify-end-safe 工具类将项目沿容器主轴末端对齐:

调整容器大小以查看对齐行为

justify-end

01
02
03
04

justify-end-safe

01
02
03
04
justify-end
<div class="flex justify-end ...">  <div>01</div>  <div>02</div>  <div>03</div>  <div>03</div></div>
justify-end-safe
<div class="flex justify-end-safe ...">  <div>01</div>  <div>02</div>  <div>03</div>  <div>03</div></div>

当可用空间不足时,justify-end-safe 工具类会将项目对齐到容器起始端而非末端。

元素间等距排列

使用 justify-between 工具类使项目沿容器主轴均匀分布,每个项目之间留有相等的间距:

01
02
03
<div class="flex justify-between ...">  <div>01</div>  <div>02</div>  <div>03</div></div>

元素周围等距排列

使用 justify-around 工具类使项目沿容器主轴均匀分布,每个项目两侧留有相等的间距:

01
02
03
<div class="flex justify-around ...">  <div>01</div>  <div>02</div>  <div>03</div></div>

均匀分布

使用 justify-evenly 工具类沿容器主轴均匀分布项目,使每个项目周围的空间相等,同时考虑了使用 justify-around 时通常会在项目之间看到的双倍间距:

01
02
03
<div class="flex justify-evenly ...">  <div>01</div>  <div>02</div>  <div>03</div></div>

拉伸填充

使用 justify-stretch 工具类允许内容项目沿容器主轴填充可用空间:

01
02
03
<div class="flex justify-stretch ...">  <div>01</div>  <div>02</div>  <div>03</div></div>

默认对齐 (Normal)

使用 justify-normal 工具类将内容项打包到它们的默认位置,就像没有设置 justify-content 值一样:

01
02
03
<div class="flex justify-normal ...">  <div>01</div>  <div>02</div>  <div>03</div></div>

响应式设计

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

<div class="flex justify-start md:justify-between ...">  <!-- ... --></div>

Learn more about using variants in the variants documentation.

Copyright © 2025 Tailwind Labs Inc.·Trademark Policy