V1: display: box;
- Chrome
- Firefox 2
- Safari 3+
- Android
- Blackberry v7+
- prefix for all
V2: display: flexbox;
- IE 10
- -ms- for IE 10
Final: display: flex;
- Chrome
- Safari 6+
- Firefox
- Opera
- IE 11
- Android 4.4
- Blackberry 10+
- Prefix for BB and Safari
V1: display: box;
V2: display: flexbox;
Final: display: flex;
Used to position horizontal and vertical stacks.
.box { display: box; box-orient:; } .box .one, .box .two { box-flex: 1; } .box .three { box-flex: 3; }
.box { display: box; box-pack: ; box-align: ; }
display: box ;
box-orient: horizontal | vertical | inherit;
box-pack: start | end | center | justify;
box-align: start | end | center | baseline | stretch;
box-flex: integer | 0;
box-flex-group
box-ordinal-group
box-direction: normal | reverse | inherit;
box-lines:
display: flexbox | inline-flexbox;
flex-direction: lr | rl | tb | bt | inline | inline-reverse | block | block-reverse flex-order: integer | 1; flex-pack: start | end | center | justify; flex-align: auto | baseline;
v2 = 2012. The spec syntax changed drastically.
CSS Flexible Box Layout Module
dev.w3.org/csswg/css-flexbox/row | row-reverse | column | column-reverse
Related properties:
flex
and inline-flex
. Used on parent to create the flex container.[flex-basis flex-grow, and flex-shrink
, or none
row
, row-reverse
, column
or columns-reverse
on the parentflex-direction
and flex-wrap
properties.nowrap
, wrap
or wrap-reverse
display: flex;
to the parent of the elements to be flexed.flex-direction
to horizontal or verticalflex-wrap
to control wrap directiondisplay
property
inline | block | list-item | inline-list-item | inline-block | table | inline-table | table-cell | table-caption | flex | inline-flex | grid | inline-grid
display: flex;
block-level flex container box
display: inline-flex;
inline-level flex container box
display
propertyflex-direction
propertyrow | row-reverse | column | column-reverse
flex-driection: ...
flex-wrap
propertynowrap | wrap | wrap-reverse
Purpose: is the whole shebang on one line, or can it wrap if necessary
flex-wrap: ...
flex-flow
propertyShorthand for flex-direction
and flex-wrap
flex-flow: ...
order
propertydiv:nth-of-type(3n) { order: -1; }
The default value is 0. Anything lower will come before those without set values. Anything above will come after.
order: ...
flex
shorthandflex-grow
:
How to divide the extra space. Non-negative number. default: 1.
flex-shrink
:
How to shrink if there's not enough room. Non-negative number. default: 1.
flex-basis
:
the
starting size
before free
space is
distributed. length value, content or auto
. If set to auto
, sets to flex item’s main size property.
flex
shorthand propertyflex
gotcha!justify-content
propertyflex-start | flex-end | center | space-between | space-around
aligns flex items
justify-content
propertyalign-items, align-content
properties
flex-start | flex-end | center | baseline | stretch
align-items
propertyul { display: flex; } li { flex: 1; }
calc()
width: calc(50% - 40px); background: linear-gradient( black calc(50% - 2px), white calc(50% - 2px), white calc(50% + 2px), black calc(50% + 2px));
width of objects:
figure > :not(figcaption) { width: calc(100% - 40px); }
also consider
figure { box-sizing: border-box; }
box-sizing: content-box | border-box
div { width: 200px; height:100px; padding: 20px; margin:20px; border-width: 5px; }
border-box replicates the old IE box model
min()
width: min(100px, 100%); width: min(90px + 50px, 30%);
max()
width: max(100px, 100%); width: max(90px + 50px, 30%)
toggle()
em { font-style: toggle(normal, italic); }