CSS justify-items eigenschap
- 上一页 justify-content
- Volgende pagina justify-self
Definition and Usage
The justify-items attribute is set on the grid container to align child elements (grid items) in the inline direction.
For English pages, the inline direction is from left to right, and the block direction is downward.
For this attribute to have any alignment effect, the grid item must have available space around itself in the inline direction.
Tip:To align grid items in the block direction instead of the inline direction, use align-items attribute Attributes.
See also:
CSS Tutorial:CSS Grid
CSS Tutorial:CSS Positioning
CSS Reference Manual:align-items attribute
CSS Reference Manual:direction attribute
CSS Reference Manual:grid attribute
CSS Reference Manual:grid-template-columns attribute
CSS Reference Manual:justify-self attribute
CSS Reference Manual:position attribute
CSS Reference Manual:writing-mode attribute
Instance
Example 1
Align each grid item at the end of its grid cell along the inline direction:
#container { display: grid; justify-items: end; }
Example 2: Comparison of justify-items and justify-self
The alignment relative to the container is set to 'centered', and the grid item itself is set to 'right aligned'. The attribute value 'right' takes precedence:
#container { display: grid; justify-items: center; } .blue { justify-self: right; }
Example 3: Set justify-items on an absolutely positioned grid item
Set the alignment of the grid items with absolute positioning to 'right aligned':
#container { display: grid; position: relative; justify-items: right; } .blue { position: absolute; }
Example 4: writing-mode
When the writing-mode attribute value of the grid container element is set to vertical-rl, the inline direction is downward. The result is that the container's starting point moves from the left to the top, and the container's end moves from the right to the bottom:
#container { justify-items: end; writing-mode: vertical-rl; }
Voorbeeld 5: richting
当网格容器元素的 direction 属性值设置为“rtl”时,行内方向是从右到左。结果是容器的起点从左侧移到右侧,容器的末端从右侧移到左侧:
#container { justify-items: start; direction: rtl; }
CSS 语法
justify-items: legacy|normal|stretch|positional alignment|overflow-alignment|baseline alignment|initial|inherit;
属性值
值 | 描述 |
---|---|
legacy |
默认值。 仅在以'legacy'开头时,justify-self 值为'auto'的网格项继承网格容器的 justify-items 属性值。 它的存在是为了实现 HTML 的 <center> 元素和 align 属性的遗留对齐行为。 |
normal | 取决于布局上下文,但类似于网格布局的 'stretch'。 |
stretch | 如果未设置 inline-size(宽度),则拉伸以填充网格单元格。 |
start | 在行内方向开头对齐项目。 |
left | 将项目左对齐。 |
center | 将项目对齐到中心。 |
end | 在行内方向的末尾对齐项目。 |
right | 将项目右对齐。 |
overflow-alignment |
|
baseline-alignment | 元素与父元素的基线对齐。 |
initial | 将此属性设置为其默认值。参阅 initial。 |
inherit | 从其父元素继承此属性。参阅 inherit。 |
技术细节
默认值: | legacy |
---|---|
继承: | 否 |
动画制作: | 不支持。请参阅:动画相关属性。 |
版本: | CSS3 |
JavaScript 语法: | object.style.justifyItems="center" |
浏览器支持
表中的数字注明了首个完全支持该属性的浏览器版本。
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | IE / Edge | Firefox | Safari | Opera |
57.0 | 16.0 | 45.0 | 10.1 | 44.0 |
- 上一页 justify-content
- Volgende pagina justify-self