百科狗-知识改变命运!

justify-self - 沿适当轴对齐的方式 - css 弹性盒子布局

百变鹏仔2年前 (2023-11-21)阅读数 21#技术干货
文章标签属性

justify-self

版本:CSS3

CSS justify-self属性,设置框在其对齐容器内沿适当轴对齐的方式。

该属性的作用效果取决于我们使用的布局模式:

justify-self - 沿适当轴对齐的方式 - css 弹性盒子布局

  • 在块级布局中,会将其包含的项目在其行内轴上对齐。
  • 绝对定位的元素中,会将其包含的项目在其行内轴上对齐,同时考虑 top、left、bottom、right 的值。
  • 表格单元中,该属性被忽略。
  • 弹性盒子布局中,该属性被忽略。
  • 网格布局中,会将其网格区域内的项目在其行内轴上对齐。

示例

/* Basic keywords */
justify-self: auto;
justify-self: normal;
justify-self: stretch;

/* Positional alignment */
justify-self: center;     /* Pack item around the center */
justify-self: start;      /* Pack item from the start */
justify-self: end;        /* Pack item from the end */
justify-self: flex-start; /* Equivalent to 'start'. Note that justify-self is ignored in Flexbox layouts. */
justify-self: flex-end;   /* Equivalent to 'end'. Note that justify-self is ignored in Flexbox layouts. */
justify-self: self-start;
justify-self: self-end;
justify-self: left;       /* Pack item from the left */
justify-self: right;      /* Pack item from the right */

/* Baseline alignment */
justify-self: baseline;
justify-self: first baseline;
justify-self: last baseline;

/* Overflow alignment (for positional alignment only) */
justify-self: safe center;
justify-self: unsafe center;

/* Global values */
justify-self: inherit;
justify-self: initial;
justify-self: unset;

浏览器支持

IE11版本浏览器都支持justify-items

语法

justify-items:normal|auto|stretch||?| left | right ]| legacy | legacy &&[ left | right | center ]
  • =[ first | last ]? baseline
  • = unsafe | safe
  • = center | start | end | self-start | self-end | flex-start | flex-end

此属性可以采用四种不同的形式之一:

  • 关键词:关键字 normal,auto,或 stretch 任选其一。
  • 基线对齐:关键词 baseline ,可选 first 或 last 之一为前缀。
  • 位置对齐:关键词 center,start,end,flex-start,flex-end,self-start,self-end,left 或 right 任选其一,可选 safe 或 unsafe 之一为前缀。
  • legacy alignment:legacy 关键字,后跟 left 或 right 之一。

取值

auto使用的值是父元素的justify-items属性的值,除非该方框没有父元素,或者是绝对定位的,在这些情况下,auto代表normalnormal这个关键字的效果取决于我们所处的布局模式:
  • 在块级布局中,相当于是start
  • In absolutely-positioned layouts, the keyword behaved likestartonreplacedabsolutely-positioned boxes, and asstretchonall otherabsolutely-positioned boxes.
  • In table cell layouts, this keyword has no meaning as this property isignored.
  • In flexbox layouts, this keyword has no meaning as this property isignored.
  • In grid layouts, this keyword leads to a behavior similar to the one ofstretch, except for boxes with an aspect ratio or an intrinsic sizes where it behaves likestart.
startThe item is packed flush to each other toward the start edge of the alignment container in the appropriate axis.endThe item is packed flush to each other toward the end edge of the alignment container in the appropriate axis.flex-startFor items that are not children of a flex container, this value is treated likestart.flex-endFor items that are not children of a flex container, this value is treated likeend.self-startThe item is packed flush to the edge of the alignment container of the start side of the item, in the appropriate axis.self-endThe item is packed flush to the edge of the alignment container of the end side of the item, in the appropriate axis.centerThe items are packed flush to each other toward the center of the of the alignment container.leftThe items are packed flush to each other toward the left edge of the alignment container. If the property’s axis is not parallel with the inline axis, this value behaves likestart.rightThe items are packed flush to each other toward the right edge of the alignment container in the appropriate axis. If the property’s axis is not parallel with the inline axis, this value behaves likestart.baseline
first baseline

last baselineSpecifies participation in first- or last-baseline alignment: aligns the alignment baseline of the box’s first or last baseline set with the corresponding baseline in the shared first or last baseline set of all the boxes in its baseline-sharing group.
The fallback alignment forfirst baselineisstart, the one forlast baselineisend.stretchIf the combined size of the items is less than the size of the alignment container, anyauto-sized items have their size increased equally(not proportionally), while still respecting the constraints imposed bymax-height/max-width(or equivalent functionality), so that the combined size exactly fills the alignment container.safeIf the size of the item overflows the alignment container, the item is instead aligned as if the alignment mode werestart.unsafeRegardless of the relative sizes of the item and alignment container, the given alignment value is honored.legacyMakes the value inherited by the box descendants. Note that if a descendant has ajustify-self: autovalue, thelegacykeyword is not considered by the descend, only theleft,right, orcentervalue associated to it.
默认值auto
适用于块级盒子、定位盒子、网格项
继承性
动画性visual
计算值指定值

例子

justify-self: stretch;
justify-self: center;
justify-self: start;
justify-self: end;

内容声明:本文中引用的各种信息及资料(包括但不限于文字、数据、图表及超链接等)均来源于该信息及资料的相关主体(包括但不限于公司、媒体、协会等机构)的官方网站或公开发表的信息。部分内容参考包括:(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供参考使用,不准确地方联系删除处理!本站为非盈利性质站点,本着为中国教育事业出一份力,发布内容不收取任何费用也不接任何广告!)
{if $zbp->Config('yd1125')->foot}