flex-start (default): items are packed toward the start line
flex-end: items are packed toward to end line
center: items are centered along the line
space-between: items are evenly distributed in the line; first item is on the start line, last item on the end line ----- 第一个 item 贴着起始边(start line),最后一个 item 贴着结束边(end line)。其余 items 的空白区域平均分配。
space-around: items are evenly distributed in the line with equal space around them. Note that visually the spaces aren't equal, since all the items have equal space on both sides. The first item will have one unit of space against the container edge, but two units of space between the next item because that next item has its own spacing that applies. --- 所有 item 含有相同的外边距,相邻的外边距不会合并。
space-evenly: items are distributed so that the spacing between any two items (and the space to the edges) is equal. --- 包括起始边和结束边到 item 的间距和所有间隔 item 的间距全部相等。
Css flexbox
[TOC]
css flexbox 由外层 container 和内部的 item 组成。
contaienr property
display
display
定义在 container(parent) 元素上。有如下两种属性:display-direction
item 的排列方向。
上面属性对应的是:
rtl
时反向rtl
时反向rtl
时反向rtl
时反向flex-wrap
定义 item 是否换行。
flex-flow
flex-direction
和flex-wrap
的缩写 propertyjustify-content
定义 items 在主轴的排列方式。此属性最重要的作用是当 items 不全是 flex 元素或者全是 flex 元素但是超出了一列的最大宽度时进行分配多余的空白空间。
align-items
定义 flex items 在交叉轴(cross axis)上的排列方式。可以把
align-items
看作是justify-content
的交叉轴版本。align-content
此属性和
justify-content
很像,不同的是align-cotent
是将多列 items 看作一个 item-container,并且在交叉轴上分配空白区域。需要注意的是,如果 items 只有一列的话此属性没有任何效果的。(?????待理解)
flex item propery
Note that
float
,clear
andvertical-align
have no effect on a flex item!!!!order
item 排列的顺序。
flex-grow
规定特定的 flex-item 会被分配到的比例,数值越大分配的比例越大。负数是非法单位。
如果所有 flex-item 都被设置为
flex-grow:1
则所有的 item 会被分配到同样的空间,如果其中有一个是 2,则 2 的那个 item 会被分配到双倍的空间,其余 item 平分剩下的空间。flex-shrink
类似
flex-grow
,不过作用在当超出最大宽度时对应 item 收缩的比例。同样,负数是非法单位。
flex-basis
定义分配空间之前的 flex-item 的默认大小。可以是长度单位或者一个关键字。
当此值是 0 的时候,所有的空间会按照
flex-grow
分配。如果设置为auto
,所有 item 的初始大小是基于其内容来决定的,剩余空间会按照flex-grow
分配。flex
是
flex-grow
flex-shrink
flex-basis
的缩写。默认值是1 0 auto
。建议是使用缩写的
flex
属性代替为每一个属性单独设值,就好像用margin
代替margin-<direction>
一样。align-self
此属性作为单个 flex-item 在交叉轴上的排列方式,当设置了会复写在 flex-container 上定义了的
align-items
属性。可以看到值和
align-items
完全一模一样。参考资料
a-guide-to-flexbox
css-tricks-almanac