弹性盒与网格
用于控制 flex 和 grid 项目沿容器主轴方向排列方式的工具类。
| Class | Styles |
|---|---|
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 工具类将项目沿容器主轴起始端对齐:
<div class="flex justify-start ..."> <div>01</div> <div>02</div> <div>03</div></div>使用 justify-center 或 justify-center-safe 工具类将项目沿容器主轴居中排列:
调整容器大小以查看对齐行为
justify-center
justify-center-safe
<div class="flex justify-center ..."> <div>01</div> <div>02</div> <div>03</div> <div>04</div></div><div class="flex justify-center-safe ..."> <div>01</div> <div>02</div> <div>03</div> <div>04</div></div>当可用空间不足时,justify-center-safe 工具类会将项目对齐到容器起始位置而不是居中。
使用 justify-end 或 justify-end-safe 工具类将项目沿容器主轴末端对齐:
调整容器大小以查看对齐行为
justify-end
justify-end-safe
<div class="flex justify-end ..."> <div>01</div> <div>02</div> <div>03</div> <div>03</div></div><div class="flex justify-end-safe ..."> <div>01</div> <div>02</div> <div>03</div> <div>03</div></div>当可用空间不足时,justify-end-safe 工具类会将项目对齐到容器起始端而非末端。
使用 justify-between 工具类使项目沿容器主轴均匀分布,每个项目之间留有相等的间距:
<div class="flex justify-between ..."> <div>01</div> <div>02</div> <div>03</div></div>使用 justify-around 工具类使项目沿容器主轴均匀分布,每个项目两侧留有相等的间距:
<div class="flex justify-around ..."> <div>01</div> <div>02</div> <div>03</div></div>使用 justify-evenly 工具类沿容器主轴均匀分布项目,使每个项目周围的空间相等,同时考虑了使用 justify-around 时通常会在项目之间看到的双倍间距:
<div class="flex justify-evenly ..."> <div>01</div> <div>02</div> <div>03</div></div>使用 justify-stretch 工具类允许内容项目沿容器主轴填充可用空间:
<div class="flex justify-stretch ..."> <div>01</div> <div>02</div> <div>03</div></div>使用 justify-normal 工具类将内容项打包到它们的默认位置,就像没有设置 justify-content 值一样:
<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.