Flexbox & Grid
用於控制單一 grid 項目如何沿其行內軸對齊的通用類別。
| Class | Styles |
|---|---|
justify-self-auto | justify-self: auto; |
justify-self-start | justify-self: start; |
justify-self-center | justify-self: center; |
justify-self-center-safe | justify-self: safe center; |
justify-self-end | justify-self: end; |
justify-self-end-safe | justify-self: safe end; |
justify-self-stretch | justify-self: stretch; |
使用 justify-self-auto 通用類別根據 grid 的 justify-items 屬性值對齊項目:
<div class="grid justify-items-stretch ..."> <!-- ... --> <div class="justify-self-auto ...">02</div> <!-- ... --></div>使用 justify-self-start 通用類別將 grid 項目對齊其行內軸的起點:
<div class="grid justify-items-stretch ..."> <!-- ... --> <div class="justify-self-start ...">02</div> <!-- ... --></div>使用 justify-self-center 或 justify-self-center-safe 通用類別將 grid 項目沿其行內軸置中對齊:
調整容器大小以查看對齊行為
justify-self-center
justify-self-center-safe
<div class="grid justify-items-stretch ..."> <!-- ... --> <div class="justify-self-center ...">02</div> <!-- ... --></div><div class="grid justify-items-stretch ..."> <!-- ... --> <div class="justify-self-center-safe ...">02</div> <!-- ... --></div>當可用空間不足時,justify-self-center-safe 通用類別會將項目對齊到容器起點而非中心。
使用 justify-self-end 或 justify-self-end-safe 通用類別將 grid 項目對齊其行內軸的終點:
調整容器大小以查看對齊行為
justify-self-end
justify-self-end-safe
<div class="grid justify-items-stretch ..."> <!-- ... --> <div class="justify-self-end ...">02</div> <!-- ... --></div><div class="grid justify-items-stretch ..."> <!-- ... --> <div class="justify-self-end-safe ...">02</div> <!-- ... --></div>當可用空間不足時,justify-self-end-safe 通用類別會將項目對齊到容器起點而非終點。
使用 justify-self-stretch 通用類別將 grid 項目伸展以填滿其行內軸上的 grid 區域:
<div class="grid justify-items-start ..."> <!-- ... --> <div class="justify-self-stretch ...">02</div> <!-- ... --></div>在 justify-self 通用類別前面加上像 md: 這樣的中斷點變體,讓該通用類別只在中型螢幕尺寸及以上時套用:
<div class="justify-self-start md:justify-self-end ..."> <!-- ... --></div>在變體文件中了解更多關於使用變體的資訊。