弹性盒子与网格
用于控制弹性布局和网格项目在容器主轴上的位置的工具类。
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.