-1

I have a html code

<div class="main">
  <div class="child1">I'm working Child 1</div>
  <div class="child2" >I'm working Child 2</div>
  <div class="child3" >I'm working Child 3</div>
</div>
<div class="another">
 <div class="child111">I'm working Child 111</div>
</div>

now I want to show Child111 before Child2 but after Child1 via CSS

Asad Khan
  • 101
  • 6

3 Answers3

1

You can do this easily by using Flexbox and setting flex-direction: column-reverse; on the parent container. It will reverse the order of its children.

Read more about Flexbox at MDN.

.main {
  display: flex;
  flex-direction: column-reverse;
}
<div class="main">
  <div class="child1">I'm working Child 1</div>
  <div class="child2">I'm working Child 2</div>
</div>
Roy
  • 7,811
  • 4
  • 24
  • 47
0

You can use grid and grid-template-areas where you can custom place the order or column with grid-area. grid-area gives you a visual representation of how the rows should appear and allows you to name the rows for better readability:

.main {
  display: grid;
  grid-template-areas:
      "first-row"
      "second-row"
  ;
}

.child1 {
  grid-area: first-row;
}

.child2 {
  grid-area: second-row;
}

Read more here: https://developer.mozilla.org/en-US/docs/Web/CSS/grid-area

Dylan Kerler
  • 2,007
  • 1
  • 8
  • 23
0

And yet another possibility:

.main>div{ float: left;}

or

.main>div{ float: right;}
Michel
  • 4,076
  • 4
  • 34
  • 52