Flexbox & Grid
用於控制 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="grid grid-cols-[4rem_auto_4rem] 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>在 justify-content 通用類別前面加上像 md: 這樣的中斷點變體,讓該通用類別只在中型螢幕尺寸及以上時套用:
<div class="flex justify-start md:justify-between ..."> <!-- ... --></div>在變體文件中了解更多關於使用變體的資訊。