Default behavior

No flexing here

A
B
C
D

Flex Container Properties

To turn on flex behavior for a container, you must set display: flex; on the container in CSS.

Default flexing (display: flex;)

A
B
C
D

There are four Flex Container properties we'll learning about in our class. These properties are: flex-direction, flex-wrap, justify-content, and align-items

These properties can only be used on elements that also have display: flex; set on them.

Flex Direction examples

This flex property specifies the main axis for the flexbox, and by extension, the cross axis as well.

For example, if you set flex-direction to be a row, then the main axis is horizontal, while the cross axis is vertical.

This is important to know, because some flex properties affect the main axis, while other affect cross axis.

flex-direction: row;

A
B
C
D

flex-direction: row-reverse;

A
B
C
D

flex-direction: column;

A
B
C
D

flex-direction: column-reverse;

A
B
C
D

Flex Wrap examples

This flex property tell flex whether or not to wrap along the main axis.

Note: if you want to wrap vertically (i.e. with a column specified as the main axis), you'll need to specify an explicit or max height.

flex-wrap: nowrap;

A
B
C
D
E
F

flex-wrap: wrap;

A
B
C
D
E
F

flex-wrap: wrap-reverse;

A
B
C
D
E
F

Flex Justify Content examples

This flex property specifies the alignment along the main axis.

justify-content: flex-start;

A
B
C

justify-content: flex-end;

A
B
C

justify-content: center;

A
B
C

justify-content: space-between;

A
B
C

justify-content: space-around;

A
B
C

justify-content: space-evenly;

A
B
C

Flex Align Items examples

This flex property specifies the alignment along the cross axis.

align-items: flex-start;

A
B
C
D
E
F

align-items: flex-end;

A
B
C
D
E
F

align-items: center;

A
B
C
D
E
F

align-items: stretch; (only stretches if heights aren't set)

A
B
C
D
E
F

align-items: baseline; (tries to fit all text on same line)

A
B
C
D
E
F