given a HTML of:
<div class="class">1</div>
<div class="class">2</div>
<div class="class">3</div>
<div class="class">4</div>
I know I can do a display:flex
together with:
.class :nth-child(1) { order: 2 }
.class :nth-child(2) { order: 4 }
.class :nth-child(3) { order: 1 }
.class :nth-child(4) { order: 3 }
which should produce
<div class="class">3</div>
<div class="class">1</div>
<div class="class">4</div>
<div class="class">2</div>
Is there a way to do this without using the flexbox in combination with its order property?
You can use grid layout, which has similar order properties.
.boxes {
display: grid;
}
.class:nth-of-type(1) {
order: 2;
}
.class:nth-of-type(2) {
order: 4;
}
.class:nth-of-type(3) {
order: 1;
}
.class:nth-of-type(4) {
order: 3;
}
<div class="boxes">
<div class="class">1</div>
<div class="class">2</div>
<div class="class">3</div>
<div class="class">4</div>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With