1. Flexbox 和 Grid
  2. justify-content

Flexbox 和 Grid

内容对齐

用于控制弹性(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>

正常对齐

使用 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