1. The flex layout

Flex, short for Flexible Box, is designed to provide maximum flexibility to Box models

With Flex layout, the float, clear, and vertical-align attributes of child elements are invalidated

2. Container properties

2.1 the flex – direction

The flex-direction attribute determines the direction of the main axis (that is, the alignment of items).

  • Row (default) : The main axis is horizontal and the starting point is on the left
  • Row-reverse: The main axis is horizontal and the starting point is at the right end
  • Column: The main axis is in the vertical direction, and the starting point is in the upper edge
  • Column-reverse: the main axis is vertical and the starting point is at the bottom

2.2 the flex – wrap

By default, projects are arranged on a line (also known as an “axis”). The flex-wrap property defines how to wrap a line if an axis does not fit

  • Nowrap (default) : no line breaks
  • Wrap: The first line is at the top
  • Wrap-reverse: newline with the first line at the bottom

2.3 the flex – flow

The flex-flow property is a short form of the flex-direction and flex-wrap properties. The default value is Row Nowrap.

flex-flow: <flex-direction> || <flex-wrap>;

2.4 the justify – content

The context-content attribute defines the alignment of items on the main axis.

  • Flex-start (default) : left-aligned
  • Flex-end: right-aligned
  • Center: a center
  • Space-between: both ends are aligned with equal intervals between items
  • Space-around: Equal spacing on both sides of each item. As a result, the spacing between items is twice as large as the spacing between items and the border

2.5 the align – items

The align-items property defines how items are aligned on the cross axis

  • Stretch (default) : If the height is not set or auto is set, the project will occupy the entire height of the container
  • Flex-start: Alignment of the starting point of the cross axes
  • Flex-end: alignment of ends of crossed axes
  • Center: Alignment of the midpoint of the cross axis
  • Baseline: The baseline alignment of the first line of text of the project

2.6 the align – content

The align-content property defines the alignment of multiple axes. This property has no effect if the project has only one axis

  • Stretch (default) : Axis takes up the entire cross axis
  • Flex-start: align with the starting point of the cross axis
  • Flex-end: aligns with the end of the cross axis
  • Center: aligns with the midpoint of the intersecting axis
  • Space-between: aligned with both ends of the intersecting axes, with evenly distributed spacing between axes
  • Pace-around: The spacing on both sides of each axis is equal. Therefore, the spacing between axes is twice as large as the spacing between axes and borders

3. Subitem attributes

3.1 the order

The order attribute defines the order of items. The smaller the value is, the more advanced it is. The default value is 0

3.2 the flex – turns up

The Flex-Grow property defines the project’s zoom scale, which defaults to 0, or no zoom if there is free space

If all projects have a flex-Grow attribute of 1, they divide the remaining space equally, if any. If one project has a flex-grow attribute of 2 and all the other projects are 1, the former takes up twice as much free space as the other items

3.3 the flex – the shrink

The Flex-shrink attribute defines the scale by which a project shrinks. The default is 1, that is, if there is insufficient space, the project shrinks

If all projects have a Flex-shrink attribute of 1, they are scaled equally when space is insufficient. If the flex-shrink attribute is 0 for one project and 1 for all other projects, the former does not shrink when space is insufficient. Negative values have no effect on this property.

3.4 the flex – basis

Flex-basis defines the main size of the project before allocating extra space. Based on this property, the browser calculates whether the main axis has extra space. Its default value is Auto, the original size of the project

3.5 the flex

The flex attribute is short for flex-grow, flex-shrink, and flex-basis. The default value is 0 1 Auto. The last two attributes are optional

This property has two shortcut values: auto (1 1 auto) and None (0 0 auto).

3.6 the align – self

The align-self property allows a single item to have a different alignment than other items, overriding the align-items property. The default value is auto, which inherits the align-items property of the parent element. If there is no parent element, it equals stretch

4. Reference

Flex Layout Tutorial: Syntax section