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)
¥Examples
自动(Auto)
¥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)
¥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)
¥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)
¥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)
¥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)
¥Responsive design
在 justify-self
工具前面使用断点变体如 md:
仅在 medium 屏幕尺寸及以上时应用工具:
<div class="justify-self-start md:justify-self-end ..."> <!-- ... --></div>
请参阅 变体文档 详细了解如何使用变体。