We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
flex-flow
flex-direction
flex-wrap
justify-content
align-content
align-items
容器设置为 display: flex; 后,项目自动可设置宽高,即使是行内元素
display: flex;
有两个轴:水平轴(main-start / main-end)和交叉轴(cross-start / cross-end)
flex-direction: row(左上角) | row-reverse(右上角) | column(左上角) | column-reverse(左下角)
容器设置为 column 后,项目自身 display: flex; 时并不继承容器的设置。
column
flex-wrap: nowrap(默认) | wrap | wrap-reverse
一些特性:
容器设置了 flex-baisis: 200px;,项目设置了 width: 20px;
flex-baisis: 200px;
width: 20px;
如果不换行,项目很多的话,容器的宽度不再是 200px。
容器设置了 width: 200px;,项目设置了 width: 20px;
width: 200px;
如果不换行,项目很多的话,项目的宽度不再是 20px。
优先级
nowrap > flex-basis > width
nowrap
flex-basis
width
flex-flow: <flex-direction> || <flex-wrap>。默认:row nowrap。
flex-flow: <flex-direction> || <flex-wrap>
row nowrap
justify-content: flex-start(左对齐) | flex-end(右对齐) | center | space-between | space-around
每个水平轴上滑动,顺序不变。
space-between: 项目间距相等;两端紧贴边框
space-between
space-around: 项目间距相等;项目之间的间隔比项目与边框之间的距离大一倍
space-around
align-content: stretch | flex-start | flex-end | center | space-between | space-around
标签:多横轴线的位置
多轴线上下排序,顺序不变。
如果项目只有一根轴线,该属性不起作用。
stretch: 默认值,轴线默认充满容器
stretch
flex-start: 与交叉轴起点对齐
flex-start
flex-end: 与交叉轴终点对齐
flex-end
center: 与交叉轴中点对齐
center
space-between: 轴线间距相同;与交叉轴两端对齐
space-around: 轴线间距相同;轴线与框的距离是轴线之间距离的一半
align-items: stretch | flex-start | flex-end | center | baseline
标签:多个交叉轴上滑动
stretch: 默认值,默认充满容器高度。
height
1/2
strech
flex-start: 交叉轴起点对齐
flex-end: 交叉轴终点对齐
baseline: 项目第一行文字的基线对齐
baseline
order
flex
flex-grow
flex-shrink
align-self
order: 0。顺序。数字越小,越靠前。可以为负值
order: 0
flex-grow: 0
非贪婪
0: 不放大
如果所有项目的 flex-grow属性都为 1,则它们将等分剩余空间(如果有的话)。
如果一个项目的 flex-grow 属性为 2,其他项目都为 1,则前者占据的剩余空间将比其他项多一倍。
如果单个项目设置 flex: 1,会充满容器宽度。
flex: 1
flex-shrink: 1
1: 可以缩小
如果所有项目的 flex-shrink 属性都为 1,当空间不足时,都将等比例缩小。
如果一个项目的 flex-shrink 属性为 0,其他项目都为 1,则空间不足时,前者不缩小。
flex-basis: auto | <length>
浏览器根据这个属性,计算主轴是否有多余空间。它的默认值为 auto,即项目的本来大小。
auto
flex-basis 并不是宽度,而是占据主轴的空间,若 flex-direction: column;,项目的 flex-basis 就表现为高度,但项目本身的主轴还是 row。
flex-direction: column;
row
如果多个项目,均设置 flex-basis: 100%,但同时容器不换行,实际宽度仍然是均分的,不是 100%。
flex: none | [<flex-grow> | <flex-shrink> || <flex-basis>]
快捷值:auto: 1 1 auto; 和 none: 0 0 auto
auto: 1 1 auto;
none: 0 0 auto
资料:https://developer.mozilla.org/zh-CN/docs/Web/CSS/flex
align-self: auto | flex-start | flex-end | center | baseline | stretch
可覆盖容器设置的 algin-items。
algin-items
常见布局:left - center - right
left - center - right
left: flex: 0 0 100px;
left
flex: 0 0 100px;
right: flex: 0 0 100px;
right
center: flex: 1
The text was updated successfully, but these errors were encountered:
Sorry, something went wrong.
父:display: flex 子:其宽度由内容确定,除非 flex: 1
No branches or pull requests
容器
容器属性快速记忆 4
flex-flow
flex-direction
flex-wrap
justify-content
align-content
align-items
详解
容器设置为
display: flex;
后,项目自动可设置宽高,即使是行内元素有两个轴:水平轴(main-start / main-end)和交叉轴(cross-start / cross-end)
flex-direction: row(左上角) | row-reverse(右上角) | column(左上角) | column-reverse(左下角)
容器设置为
column
后,项目自身display: flex;
时并不继承容器的设置。flex-wrap: nowrap(默认) | wrap | wrap-reverse
一些特性:
容器设置了
flex-baisis: 200px;
,项目设置了width: 20px;
如果不换行,项目很多的话,容器的宽度不再是 200px。
容器设置了
width: 200px;
,项目设置了width: 20px;
如果不换行,项目很多的话,项目的宽度不再是 20px。
优先级
nowrap
>flex-basis
>width
flex-flow: <flex-direction> || <flex-wrap>
。默认:row nowrap
。justify-content: flex-start(左对齐) | flex-end(右对齐) | center | space-between | space-around
每个水平轴上滑动,顺序不变。
space-between
: 项目间距相等;两端紧贴边框space-around
: 项目间距相等;项目之间的间隔比项目与边框之间的距离大一倍align-content: stretch | flex-start | flex-end | center | space-between | space-around
标签:多横轴线的位置
多轴线上下排序,顺序不变。
如果项目只有一根轴线,该属性不起作用。
stretch
: 默认值,轴线默认充满容器flex-start
: 与交叉轴起点对齐flex-end
: 与交叉轴终点对齐center
: 与交叉轴中点对齐space-between
: 轴线间距相同;与交叉轴两端对齐space-around
: 轴线间距相同;轴线与框的距离是轴线之间距离的一半align-items: stretch | flex-start | flex-end | center | baseline
标签:多个交叉轴上滑动
stretch
: 默认值,默认充满容器高度。height
,会使用height
。stretch
,但如果换行了,stretch
失效,比如换为两行,高度变为原来的1/2
。strech
,则高度由内容确定。flex-start
: 交叉轴起点对齐flex-end
: 交叉轴终点对齐baseline
: 项目第一行文字的基线对齐项目属性
属性快速记忆
order
flex
flex-grow
flex-shrink
flex-basis
align-self
详解
order: 0
。顺序。数字越小,越靠前。可以为负值flex-grow: 0
非贪婪
0: 不放大
如果所有项目的
flex-grow
属性都为 1,则它们将等分剩余空间(如果有的话)。如果一个项目的
flex-grow
属性为 2,其他项目都为 1,则前者占据的剩余空间将比其他项多一倍。如果单个项目设置
flex: 1
,会充满容器宽度。flex-shrink: 1
1: 可以缩小
如果所有项目的
flex-shrink
属性都为 1,当空间不足时,都将等比例缩小。如果一个项目的
flex-shrink
属性为 0,其他项目都为 1,则空间不足时,前者不缩小。flex-basis: auto | <length>
浏览器根据这个属性,计算主轴是否有多余空间。它的默认值为
auto
,即项目的本来大小。flex-basis
并不是宽度,而是占据主轴的空间,若flex-direction: column;
,项目的flex-basis
就表现为高度,但项目本身的主轴还是row
。如果多个项目,均设置
flex-basis
: 100%,但同时容器不换行,实际宽度仍然是均分的,不是 100%。flex: none | [<flex-grow> | <flex-shrink> || <flex-basis>]
快捷值:
auto: 1 1 auto;
和none: 0 0 auto
资料:https://developer.mozilla.org/zh-CN/docs/Web/CSS/flex
align-self: auto | flex-start | flex-end | center | baseline | stretch
可覆盖容器设置的
algin-items
。练习
常见布局:
left - center - right
left
:flex: 0 0 100px;
right
:flex: 0 0 100px;
center
:flex: 1
The text was updated successfully, but these errors were encountered: