githubEdit

CSS Flex Box

Simple example

.container {
  display: flex;
}
.container > div {
  flex: 1 1 auto;
}

Container

.container {

{: .-setup}

  display: flex;
  display: inline-flex;
  flex-direction: row;            /* ltr - default */
  flex-direction: row-reverse;    /* rtl */
  flex-direction: column;         /* top-bottom */
  flex-direction: column-reverse; /* bottom-top */
  flex-wrap: nowrap; /* one-line */
  flex-wrap: wrap;   /* multi-line */
  align-items: flex-start; /* vertical-align to top */
  align-items: flex-end;   /* vertical-align to bottom */
  align-items: center;     /* vertical-align to center */
  align-items: stretch;    /* same height on all (default) */

{: .-setup}

Child

{: .-setup}

{: .-setup}

Tricks

Vertical center

Vertical center (2)

Reordering

Mobile layout

A fixed-height top bar and a dynamic-height content area.

Table-like

This creates columns that have different widths, but size accordingly according to the circumstances.

Vertical

Vertically-center all items.

Left and right

References

{: .-one-column}

Last updated