Flexbox by trial

Flexbox is CSS3 for laying out elements. Check browser support info (by caniuse.com)

Default

No styles attached, default look:

one

two

three

four

Basics

Define an OUTER container as a flex container, requires -webkit for Safari

    .class {
      display:-webkit-flex;
      display: flex;
    }
  

one

two

three

four

Flow

Flexbox can be defined as a row or as a column, so items inside the flexbox will be arranged horizontally (row) or vertically (column). Flex-direction row is set by default.

    .class {
      -webkit-flex-direction: [row|column];
      flex-direction: [row|column];
    }
  

flex-direction: column

one

two

three

four

Wrap

If flexbox container is small and requires items inside to wrap, flex-flow with wrap is required. Flex-flow also defines direction like flex-direction, so flex-direction is not required.

    .class {
      -webkit-flex-flow: row wrap;
      flex-flow: row wrap;
    }
  

no wrap

one

two

three

four

with wrap

one

two

three

four

Direction

Flex-direction specifies the direction of the flow, for rows default is left to right, reverse is right to left. Reverse works per line, not per element.

    .class {
      -webkit-flex-flow: row-reverse wrap;
      flex-flow: row-reverse wrap;
    }
  

one

two

three

four

Flex property - flexibility

Combines multiple properties and sets behaviour of the box: grow, shrink, basis. Used for layout (like column layout).

    .class {
      -webkit-flex: [grow] [shrink] [basis];
      flex-flow: [grow] [shrink] [basis];
    }
  

flex: 1

flex: 4

flex: 2

flex: 1