Summary 4

CSS Flexbox overview

Flexbox is a one-dimensional layout method for arranging items in rows or columns. It helps to distribute the space within the container efficiently. Flexbox simplifies the design process by providing better alignment, spacing, and ordering of elements compared to older layout models such as float.

Traditional layouts before Flexbox include:

Block layout – used to section large areas of content.
Inline layout – used for text and small elements
Table layout – suited for two-dimensional layouts
Positioned layout – allows the explicit placement of elements using coordinates and positioning methods.

Flex Container

A flexbox layout is created by defining a flex container, which holds flex items. Flex items can be manipulated using the flexbox properties. To define a flex container, set the containers display property to flex

.flex-container{
Display: flex;
}

Properties of flex containers

Flex-direction- determines the direction in which flex items are placed in the flex container.

Flex-wrap controls wether flex items should wrap onto multiple lines if necessary

Flex-flow is a shorthand for both flex-direction and flex-wrap. The first value defines the direction, and the second defines wrapping behavior.

Justify content: defines how flex items are aligned along the main axis

Align-items aligns flwex items along the cross-axis

Align-contenet aligns rows of flex items when there is extra space along the cross-axis