A Complete Guide to Flexbox Part 2

  • flex-basis: This defines the default size of an element before the remaining space is distributed. The main-size value makes it match the width or height, depending on which is relevant based on the flex-direction.
    If set to 0, the extra space around content isn't factored in. If set to auto, the extra space is distributed based on it's flex-grow value.

  • flex: This is the shorthand for flex-grow, flex-shrink and flex-basis combined. The second and third parameters (flex-shrink and flex-basis) are optional. Default is 0 1 auto.
    It is recommended that you use this shorthand property rather than set the individual properties. The short hand sets the other values intelligently.

  • justify-content: This defines the alignment along the main axis. It helps distribute extra free space left over 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.

  • flex-start (default): items are packed toward the start line

  • flex-end: items are packed toward to end line center: items are centered along the line

  • space-between: items are evenly distributed in the line; first item is on the start line, last item on the end line.

  • space-around: items are evenly distributed in the line with equal space around them. Note that visually the spaces aren't equal, since all the items have equal space on both sides. The first item will have one unit of space against the container edge, but two units of space between the next item because that next item has it's own spacing that applies.

Note that float, clear and vertical-align have no effect on a flex item.

  • align-items: This defines the default behaviour for how flex items are laid out along the cross axis on the current line. Think of it as the justify-content version for the cross-axis (perpendicular to the main-axis).

  • flex-start: cross-start margin edge of the items is placed on the cross-start line

  • flex-end: cross-end margin edge of the items is placed on the cross-end line

  • center: items are centered in the cross-axis baseline: items are aligned such as their baselines align

  • stretch (default): stretch to fill the container (still respect min-width/max-width)

  • align-content: This aligns a flex container's lines within when there is extra space in the cross-axis, similar to how justify-content aligns individual items within the main-axis.

Note: this property has no effect when there is only one line of flex items.

  • flex-start: lines packed to the start of the container
  • flex-end: lines packed to the end of the container
  • center: lines packed to the center of the container
  • space-between: lines evenly distributed; the first line is at the start of the container while the last one is at the end
  • space-around: lines evenly distributed with equal space around each line
  • stretch (default): lines stretch to take up the remaining space