Computer >> Computer tutorials >  >> Programming >> CSS

Enable Wrapping of Flex Items using CSS3


To enable wrapping of Flex Items using CSS3, the flex-wrap property is used. Set the value wrap to enable wrapping.

Following is the code for enabling wrapping of flex items using CSS3 −

Example

<!DOCTYPE html>
<html>
<head>
<style>
body {
   font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}
.container {
   height: 300px;
   display: flex;
   width: 300px;
   border: 2px solid red;
   flex-wrap: wrap;
}
div {
   width: 150px;
   height: 100px;
   color: white;
   text-align: center;
   font-size: 20px;
}
.first {
   background-color: rgb(55, 0, 255);
}
.second {
   background-color: red;
}
.third {
   background-color: rgb(140, 0, 255);
}
</style>
</head>
<body>
<h1>Flex wrap example</h1>
<div class="container">
<div class="first">First Div</div>
<div class="second">Second Div</div>
<div class="third">Third Div</div>
</div>
</body>
</html>

Output

Enable Wrapping of Flex Items using CSS3

The above code will produce the following output −