Flexbox 和 Grid
justify-self
用于控制单个网格项在其内联轴上对齐方式的工具。
| 类 | 样式 |
|---|---|
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; |
示例(Examples)
自动(Auto)
使用 justify-self-auto 工具根据网格的 justify-items 属性值对项目进行对齐:
🌐 Use the justify-self-auto utility to align an item based on the value of the grid's justify-items property:
<div class="grid justify-items-stretch ..."> <!-- ... --> <div class="justify-self-auto ...">02</div> <!-- ... --></div>开始(Start)
使用 justify-self-start 工具将网格项对齐到其内联轴的起点:
🌐 Use the justify-self-start utility to align a grid item to the start of its inline axis:
<div class="grid justify-items-stretch ..."> <!-- ... --> <div class="justify-self-start ...">02</div> <!-- ... --></div>中心(Center)
使用 justify-self-center 或 justify-self-center-safe 工具将网格项目沿其内联轴居中对齐:
🌐 Use the justify-self-center or justify-self-center-safe utilities to align a grid item along the center of its inline axis:
调整容器大小以查看对齐行为
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 工具会将项目对齐到容器的起始位置,而不是结束位置。
🌐 When there is not enough space available, the justify-self-center-safe utility will align the item to the start of the container instead of the end.
结尾(End)
使用 justify-self-end 或 justify-self-end-safe 工具将网格项目对齐到其内联轴的末端:
🌐 Use the justify-self-end or justify-self-end-safe utilities to align a grid item to the end of its inline axis:
调整容器大小以查看对齐行为
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 工具会将项目对齐到容器的起始位置,而不是结束位置。
🌐 When there is not enough space available, the justify-self-end-safe utility will align the item to the start of the container instead of the end.
拉紧(Stretch)
使用 justify-self-stretch 工具将网格项沿其内联轴拉伸以填充网格区域:
🌐 Use the justify-self-stretch utility to stretch a grid item to fill the grid area on its inline axis:
<div class="grid justify-items-start ..."> <!-- ... --> <div class="justify-self-stretch ...">02</div> <!-- ... --></div>响应式设计(Responsive design)
在 justify-self 工具前面使用断点变体如 md: 仅在 medium 屏幕尺寸及以上时应用工具:
<div class="justify-self-start md:justify-self-end ..."> <!-- ... --></div>请参阅 变体文档 详细了解如何使用变体。