The container is the parent element that contains a set of flex items. To create a flex container, set the display
property of the parent element to flex
or inline-flex
.
Flex items are the child elements inside the flex container. They can be any HTML element, and each item can have its own unique properties. Flex items are arranged in a single line, called the “main axis”, and a perpendicular line, called the “cross axis”.
The flex-direction
property determines the direction of the main axis. It can be set to row
(the default), row-reverse
, column
or column-reverse
.
The justify-content
property aligns items along the main axis. It can be set to flex-start
(the default), flex-end
, center
, space-between
, space-around
, or space-evenly
.
The align-items
property aligns items along the cross axis. It can be set to stretch
(the default), flex-start
, flex-end
, center
, baseline
, or first baseline
.
The align-content
property aligns the space between the flex lines. It can be set to stretch
(the default), flex-start
, flex-end
, center
, space-between
, space-around
, or space-evenly
.
The flex-grow
, flex-shrink
, and flex-basis
properties are used to set the size of the flex items. Flex-grow
determines how much the item grows relative to the other items, flex-shrink
determines how much the item shrinks relative to the other items, and flex-basis
sets the initial size of the item.
The flex-wrap
property determines whether the flex items are forced onto a single line or can wrap onto multiple lines. It can be set to nowrap
(the default), wrap
, or wrap-reverse
.
The flex-flow
shorthand property combines the flex-direction
and flex-wrap
properties into a single declaration.
The order
property determines the order in which the flex items appear within the container. Items with a lower order value appear first.
flex-direction
property, which can have values of row
, row-reverse
, column
, or column-reverse
.display
property of the parent container must be set to flex
in order to create a flex container.justify-content
property is used to align items along the main axis.align-items
property is used to align items along the cross axis.flex-wrap
property is used to wrap items onto multiple lines if they can’t all fit in a single line.flex
property is a shorthand property that allows you to set the flex-grow
, flex-shrink
, and flex-basis
properties in a single line.flex-grow
property specifies how much the flex item should grow relative to the other items in the container.flex-shrink
property specifies how much the flex item should shrink relative to the other items in the container.flex-basis
property specifies the initial size of the flex item before any available space is distributed.align-self
property is used to align a single flex item along the cross axis.Flexbox is designed for one-dimensional content, meaning it arranges content in a single line.
The main axis is the line along which flex items are arranged, either horizontally or vertically, while the cross axis is perpendicular to the main axis.
Certain properties of flexbox, such as order, can negatively impact accessibility when the visual order is not the same as the logical order.
Advantages of using flexbox over float include easier centering of content, automatic equalizing of container heights, and better support for responsive design.
I may be able to use flexbox to create a boggle / tangleword clone I am working on. However, I think that the grid system may be better.