--- title: justify-items slug: Web/CSS/justify-items translation_of: Web/CSS/justify-items ---
CSS 的 justify-items
属性为所有盒中的项目定义了默认的 {{CSSxRef("justify-self")}} , 可以使这些项目以默认方式沿适当轴线对齐到每个盒子。
该属性的作用效果取决于我们使用的布局模式:
/* Basic keywords */ justify-items: auto; justify-items: normal; justify-items: stretch; /* Positional alignment */ justify-items: center; /* Pack items around the center */ justify-items: start; /* Pack items from the start */ justify-items: end; /* Pack items from the end */ justify-items: flex-start; /* Pack flex items from the start */ justify-items: flex-end; /* Pack flex items from the end */ justify-items: self-start; justify-items: self-end; justify-items: left; /* Pack items from the left */ justify-items: right; /* Pack items from the right */ /* Baseline alignment */ justify-items: baseline; justify-items: first baseline; justify-items: last baseline; /* Overflow alignment (for positional alignment only) */ justify-items: safe center; justify-items: unsafe center; /* Legacy alignment */ justify-items: legacy right; justify-items: legacy left; justify-items: legacy center; /* Global values */ justify-items: inherit; justify-items: initial; justify-items: unset;
此属性可以采用四种不同的形式之一:
normal
,auto
,或 stretch
任选其一baseline
, 可选 first
或 last
之一为前缀center
,start
,end
,flex-start
,flex-end
,self-start
,self-end
,left
或 right
任选其一,可选 safe
或 unsafe
之一为前缀 legacy
keyword, followed by one of left
or right
.auto
auto
代表 normal
。normal
start
。start
on replaced absolutely-positioned boxes, and as stretch
on all other absolutely-positioned boxes.stretch
, except for boxes with an aspect ratio or an intrinsic sizes where it behaves like start
.start
end
flex-start
start
.flex-end
end
.self-start
self-end
center
left
start
.right
start
.baseline
first baseline
last baseline
first baseline
is start
, the one for last baseline
is end
.stretch
auto
-sized items have their size increased equally (not proportionally), while still respecting the constraints imposed by {{CSSxRef("max-height")}}/{{CSSxRef("max-width")}} (or equivalent functionality), so that the combined size exactly fills the alignment container.safe
start
.unsafe
legacy
justify-self: auto
value, the legacy
keyword is not considered by the descend, only the left
, right
, or center
value associated to it.{{CSSSyntax}}
Specification | Status | Comment |
---|---|---|
{{SpecName("CSS3 Box Alignment", "#propdef-justify-items", "justify-items")}} | {{Spec2("CSS3 Box Alignment")}} | Initial definition |
{{CSSInfo}}
{{Compat("css.properties.justify-items.flex_context")}}
{{Compat("css.properties.justify-items.grid_context")}}