infuerno.github.io

Wes Bos: Flexbox

Flex direction

Wrapping

Order

Alignment and centering

justify-content

Affects the main axis (LEFT to RIGHT with default flex-direction: row).

align-items

Affects the cross axis, so if using the default direction of row, this will be from TOP to BOTTOM. Will therefore need height specified for this to work (e.g. height: 100vh).

align-content

Affects the cross axis, and specifies where any extra space should go. Therefore, only has an effect IF there are multiple rows (so probably need to set wrap).

This can be confusing, but align-content determines the spacing between lines, while align-items determines how the items as a whole are aligned within the container. When there is only one line, align-content has no effect.

align-self

Exactly like align-item but applied on an item so you can override the container’s align-items value.

Flexbox sizing with flex

What do I do with any extra space? What do I do when I don’t have enough space? At what proportion should I scale myself up or down when I have extra space or not enough space.

flex combines the following properties:

Fully specified this then becomes:

When wrapping, flex-basis, flex-grow and flex-shrink only apply to elements in the same row.

Autoprefixer

Follow instructions on npm Autoprefixer page for JavaScript and Gulp.

Useful tricks

Select all flex items

.flex-container > * {
  flex: 1 1 100%;
}