Introduction

Since flexbox is a whole module and not a single property, it involves a lot of things including its whole set of properties. Some of them are meant to be set on the container (parent element, known as “flex container”) whereas the others are meant to be set on the children (said “flex items”).

If “regular” layout is based on both block and inline flow directions, the flex layout is based on “flex-flow directions”. Please have a look at this figure from the specification, explaining the main idea behind the flex layout.

The main idea behind the flex layout is to give the container the ability to alter its items’ width/height (and order) to best fill the available space (mostly to accommodate to all kind of display devices and screen sizes). A flex container expands items to fill available free space or shrinks them to prevent overflow.

Items will be laid out following either the main axis (from main-start to main-end) or the cross axis (from cross-start to cross-end).

Display

This defines a flex container; inline or block depending on the given value. It enables a flex context for all its direct children.

.container { display: flex; }

Note that CSS columns have no effect on a flex container.

Flex Direction

This establishes the main-axis, thus defining the direction flex items are placed in the flex container. Flexbox is (aside from optional wrapping) a single-direction layout concept. Think of flex items as primarily laying out either in horizontal rows or vertical columns.

.container { flex-direction: row; }
.container { flex-direction: row-reverse; }
.container { flex-direction: column; }
.container { flex-direction: column-reverse; }
Flex Wrap

By default, flex items will all try to fit onto one line. You can change that and allow the items to wrap as needed with this property.

.container { flex-wrap: nowrap; }
.container { flex-wrap: wrap; }
.container { flex-wrap: wrap-reverse; }
Justify Content

This defines the alignment along the main axis. It helps distribute extra free space leftover when either all the flex items on a line are inflexible, or are flexible but have reached their maximum size. It also exerts some control over the alignment of items when they overflow the line.

.container { justify-content: center; }
(Full) source here