Flex-wrap is a CSS property that allows the flexible items to wrap into multiple lines or columns. It is used in conjunction with the display property set to flex or inline-flex. Flex-wrap is used to control the layout of the flex container when the items overflow the container's width or height.
The flex-wrap property has three possible values:
Let's take a look at some code examples to better understand how flex-wrap works.
In this example, we have a flex container with four items. The flex-wrap property is set to nowrap, which means that the items will not wrap and will be displayed in a single line.
.flex-container {
display: flex;
flex-wrap: nowrap;
}
.flex-item {
flex: 1;
height: 100px;
background-color: #ccc;
margin: 10px;
}
In this example, we have a flex container with six items. The flex-wrap property is set to wrap, which means that the items will wrap onto multiple lines or columns as needed.
.flex-container {
display: flex;
flex-wrap: wrap;
}
.flex-item {
flex: 1;
height: 100px;
background-color: #ccc;
margin: 10px;
}
In this example, we have a flex container with six items. The flex-wrap property is set to wrap-reverse, which means that the items will wrap onto multiple lines or columns in reverse order.
.flex-container {
display: flex;
flex-wrap: wrap-reverse;
}
.flex-item {
flex: 1;
height: 100px;
background-color: #ccc;
margin: 10px;
}
As you can see, the flex-wrap property is a powerful tool for controlling the layout of flexible items in a container. By using the wrap and wrap-reverse values, you can create complex layouts that adapt to different screen sizes and device orientations.
Flex-wrap is a CSS property that allows flexible items to wrap onto multiple lines or columns. It is used in conjunction with the display property set to flex or inline-flex. The flex-wrap property has three possible values: nowrap, wrap, and wrap-reverse. By using these values, you can control the layout of flexible items in a container and create complex layouts that adapt to different screen sizes and device orientations.