CSS
π― CSS flex-wrap Property
The flex-wrap CSS property controls whether flex items should wrap onto a new line in a Flexbox layout.
By default, flex items try to stay on a single line. flex-wrap defines what happens when they no longer fit.
πΉ Why Use flex-wrap?
-
Benefits
- π Controls whether flex items break into new rows
- π Essential for responsive design
- π Prevents overflow issues in flex layouts
- π Helps create adaptive UI components
πΉ flex-wrap Values
- nowrap β Default value, all items stay on one line
- wrap β Items move to a new line if needed
- wrap-reverse β Items wrap in reverse direction (new line goes upward)
- initial β Resets to default (nowrap)
π§© Basic Example
CSS
.container {
display: flex;
flex-wrap: wrap;
}
In this example, flex items will wrap onto new lines when they no longer fit in a single row.
-
π§ Summary
- flex-wrap controls whether flex items wrap onto new lines.
- It is essential for responsive Flexbox layouts.
- wrap is the most commonly used value.
- Helps prevent overflow and layout breaking.
