CSS Flexbox (Flexible Box Layout) is a powerful layout system that helps create responsive and flexible designs. It is mainly used to align, distribute, and arrange elements efficiently, even when their sizes are unknown.
Flexbox provides a way to distribute space among elements inside a container and align items efficiently. It consists of:
display: flex;
)
To use Flexbox, you must apply display: flex;
to the container:
.container {
display: flex;
}
✔ Now, all direct children of .container
become flex items.
display: flex;
This makes an element a flex container, allowing its children to be flexible.
flex-direction
(Main Axis Control)Defines the direction of flex items.
Value | Effect |
---|---|
row (default) |
Items are placed horizontally (left to right) |
row-reverse |
Items are placed horizontally (right to left) |
column |
Items are placed vertically (top to bottom) |
column-reverse |
Items are placed vertically (bottom to top) |