Flex

Flex allows users to build Flexible Box Module based layouts. It serves as a technical component that abstracts users from working directly with CSS Flexbox and helps them write more semantic layouts.

Overview

The Flex component is designed to provide a more efficient way to organize, align, and distribute space among items within a container, even when their size is unknown or dynamic (hence the term 'flex').

By leveraging the capabilities of the Flex component, developers can create more flexible and responsive layouts that adapt to different screen sizes and device types. This powerful tool enables the creation of complex structures that can be easily adjusted to accommodate various content types and user interactions.

In the sections that follow, we'll explore the core concepts and best practices for using the Flex component. By understanding these principles, you can optimize the layout of your application, enhance the user experience, and create more engaging and visually appealing interfaces.

Axes

Flexboxes are comprised mainly of two axes: the main axis and the cross axis. The main axis is defined by the flex-direction property, and the cross axis runs perpendicular to it.

  • The main axis is defined by flex-direction, which has four possible values: row, row-reverse, column and column-reverse.
  • The cross axis runs perpendicular to the main axis.
    • If the flex-direction (main axis) is set to row or row-reverse the cross axis runs down the columns.
    • If the flex-direction is set to column or column-reverse, the cross axis runs down the rows.

Start and end

The flexbox makes no assumption about the writing mode of the document. Left to right or right to left can be used depending, for example, on the language used. A start and end edge is used to refer to the direction of the placement of elements.

For example, If the flex-direction is row and the language is English, then the start edge of the main axis will be on the left, the end edge on the right.

Flexbox container

An area of a document laid out using flexbox is called a flex container.

  • The items display in a row (the flex-direction property's default is row).
  • The items start from the start edge of the main axis.
  • The items do not stretch on the main dimension, but can shrink.
  • The items will stretch to fill the size of the cross axis.