0

How can I make an element visually switch position with another element using CSS? For example, if I have this HTML markup:

<html>
 <body>
    <div class="div1">Div1</div>
    <div class="div2">Div2</div>
    <div class="div3">Div3</div>
 </body>
</html>

I want .div3 and .div1 to switch places. How can I do this using CSS?

Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252
UAK
  • 19
  • 4

1 Answers1

4

You can do it using flexbox's order property:

.flex {
  display: flex;
}
.flex > div {
  width: 100px;
  text-align: center;
  border: 1px solid #ccc;
}
.div1 {order: 3;}
.div2 {order: 2;}
.div3 {order: 1;}
<div class="flex">
  <div class="div1">Div1</div>
  <div class="div2">Div2</div>
  <div class="div3">Div3</div>
</div>

Preview:

preview

Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252