04 - Flex in CSS
04 - Flex in CSS
within a container. With Flexbox, you can easily adjust the layout and positioning of elements,
regardless of their size or content.
To use Flexbox, you first need to define a container element, and then specify the layout and
alignment properties for the items within that container. Here are the main properties you can
use:
display: flex;
This property turns the container element into a flex container and enables the use of flex
properties.
Example:
Flex-direction:
This property specifies the direction in which the items within the container should be laid out. It
can take one of four values: row (default), row-reverse, column, or column-reverse.
Example:
justify-content:
This property aligns the items along the main axis (horizontal for row and row-reverse, and
vertical for column and column-reverse). It can take one of five values: flex-start (default),
flex-end, center, space-between, or space-around.
Example:
align-items:
This property aligns the items along the cross-axis (vertical for row and row-reverse, and
horizontal for column and column-reverse). It can take one of five values: stretch (default),
flex-start, flex-end, center, or baseline.
Example:
flex-wrap:
This property specifies whether the items should wrap to the next line when they exceed the
width or height of the container. It can take one of three values: nowrap (default), wrap, or
wrap-reverse.
Example:
Flex-flow:
Example:
align-content:
This property aligns the lines of items when there is extra space in the cross-axis. It can take
one of six values: stretch (default), flex-start, flex-end, center, space-between, or space-around.
Example:
order:
This property specifies the order in which the items should be displayed within the container.
The default value is 0.
Example:
flex-grow:
This property specifies how much the item should grow relative to the other items in the
container. The default value is 0.
Example:
flex-shrink:
This property specifies how much the item should shrink relative to the other items in the
container. The default value is 1.
Example:
flex-basis:
This property specifies the initial size of the item before any remaining space is distributed. The
default value is auto.
Example:
flex:
Example: