CSS

对齐项目 | justify-items

justify-items

justify-items属性为所有箱子定义了默认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;

语法

该属性可以采取四种不同的形式之一:

  • 基本关键字:关键字值之一normalautostretch

  • 基线对齐:baseline关键字,以及可选的一个firstlast

  • 位置对准:一centerstartendflex-startflex-endself-startself-endleft,或right。另外可选safeunsafe

  • 旧版对齐:legacy关键字,后跟一个leftright

auto使用的值是"父"框的justiy-items属性的值,除非该框没有父级或绝对定位,在这些情况下,auto表示正常.normal此关键字的效果与我们所在的布局模式相关:

  • 在块级布局中,关键字是一个同义词start

  • 在绝对定位的布局中, 关键字的表现就像在替换绝对定位的框上, 以及在所有其他绝对定位的框上。

  • 在表格单元布局中,这个关键字没有意义,因为这个属性被忽略

  • 在flexbox布局中,此关键字没有意义,因为此属性被忽略。

  • 在网格布局中,这个关键字会导致类似的行为stretch,除了具有宽高比的方框或其行为类似的内在尺寸外start

start在适当的轴线上朝向对齐容器的起始边缘彼此齐平地包装。

这仅适用于柔性布局项目。对于不是弹性容器的子项的项目,这个值被视为像start

这仅适用于柔性布局项目。对于不是弹性容器的子项的项目,这个值被视为像end

first baseline

last baseline指定参与首次或最后一次基线对齐:将框的第一个或最后一个基准集的对齐基线与基准线共享组中所有框的共享第一个或最后一个基准线集中的相应基线对齐。

first baseline回退定位是start,一只为last baselineend

规范

SpecificationStatusComment
CSS Box Alignment ModuleThe definition of 'justify-items' in that specification.Working DraftInitial definition

浏览器兼容性

FeatureFirefox (Gecko)ChromeEdgeInternet ExplorerOperaSafari
Basic support45 (45)?????

FeatureFirefox Mobile (Gecko)AndroidAndroid WebviewEdgeIE PhoneOpera MobileSafari MobileChrome for Android
Basic support45.0 (45)???????