Category: javascript
css flexbox layouts alignment wrapping
Published on 30 Sep 2026
Explanation
Flexbox is a one-dimensional CSS layout system used to arrange elements in a row or column.
Code:
.container {
display: flex;
}
.item {
padding: 20px;
}
Explanation
flex-direction controls whether flex items are arranged horizontally or vertically.
Code:
.container {
display: flex;
flex-direction: row;
}
/* row | row-reverse | column | column-reverse */
Explanation
justify-content controls alignment along the main axis.
Code:
.container {
display: flex;
justify-content: space-between;
}
Explanation
align-items controls alignment along the cross axis.
Code:
.container {
display: flex;
align-items: center;
height: 200px;
}
Explanation
flex-wrap allows items to move onto multiple lines when there is not enough horizontal space.
Code:
.container {
display: flex;
flex-wrap: wrap;
gap: 20px;
}
.item {
width: 200px;
}