0%

Flex小结

最近重温了下Flex,发现不用的话很快就会忘记,所以除了用传统的笔记外,再在blog上敲一下加深下印象。 :)

一个弹性盒布局是这样的:

W3C上给出的图片:

弹性盒布局W3C

个人感觉MDN给的图片看着更清楚:

弹性盒布局

1 兼容性

a. IE 8,9都不支持,10是要写 display: flexbox;

b. Chrome 20- / Safari 3.1+ / Firefox 2-21 / Android 2.1+ / iOS 3.2+ 都是09年旧的语法,需要写 display: box;

c. Chrome 21+ / Safari 6.1+ / Opera 12.1+ / IE 11+ / Android 4.4+ / iOS 7.1+ 都可采用新的 display: flex;

2 Flex Container

display: flex | inline-flex;

flex-direction: row | row-reverse | column | column-reverse;
flex-direction
flex-wrap: nowrap | wrap | wrap-reverse;
flex-wrap
flex-flow: <'flex-direction'> || <'flex-wrap'>;

justify-content: flex-start | flex-end | center | space-between | space-around;
justify-content
align-content: flex-start | flex-end | center | space-between | space-around | stretch;
align-content
align-items: flex-start | flex-end | center | baseline | stretch;
align-items

3 Flex items

order: 'integer';

order

align-self: auto | flex-start | flex-end | center | baseline | stretch;

align-self

关于Baseline:

baseline

flex-grow: 'number'; /* default 0 */

flex-grow

flex-shrink: 'number'; /* default 1 */

根据需要用来定义伸缩项目收缩的能力。[注意:负值同样生效。]

flex-basis: 'length' | auto; /* default auto */

flex-basis

flex: none | [<'flex-grow'> <'flex-shrink'> ?|| <'flex-basis'>] /* default: 0 1 auto */

相关资料:

  1. https://css-tricks.com/snippets/css/a-guide-to-flexbox/

  2. https://developer.mozilla.org/zh-CN/docs/Web/CSS/CSS_Flexible_Box_Layout/Using_CSS_flexible_boxes

  3. https://segmentfault.com/a/1190000002910324