EN
CSS - change flex items order (flexbox order)
0
points
In this article, we would like to show you how to change flex items order in CSS.
Quick solution:
.container {
display: flex;
}
.item1 {
order: 3;
}
.item2 {
order: 1;
}
.item3 {
order: 2;
}
Practical example
In this example, we use flexbox order
property to change the order of flex items inside the container.
// ONLINE-RUNNER:browser;
<!doctype html>
<html>
<head>
<style>
.container {
background-color: #3085d6;
height: 200px;
width: 200px;
border-radius: 10px;
display: flex; /* <----- required */
}
.item1 {
height: 50px;
width: 50px;
margin: 2px;
background-color: rgb(255, 195, 83);
border-radius: 5px;
text-align: center;
line-height: 50px;
order: 3; /* <----- required */
}
.item2 {
height: 50px;
width: 50px;
margin: 2px;
background-color: rgb(146, 255, 83);
border-radius: 5px;
text-align: center;
line-height: 50px;
order: 1; /* <----- required */
}
.item3 {
height: 50px;
width: 50px;
margin: 2px;
background-color: rgb(221, 83, 255);
border-radius: 5px;
text-align: center;
line-height: 50px;
order: 2; /* <----- required */
}
</style>
</head>
<body>
<div class="container">
<div class="item1">1</div>
<div class="item2">2</div>
<div class="item3">3</div>
</div>
</body>
</html>