Hello is there a way to reverse an order of specific child element?
<ul>
<li>A</li>
<li>B</li>
<li>C</li>
</ul>
from this to this:
<ul>
<li>A</li>
<li>C</li>
<li>B</li>
</ul>
I only want the Item C to reverse with Item B
Hello is there a way to reverse an order of specific child element?
<ul>
<li>A</li>
<li>B</li>
<li>C</li>
</ul>
from this to this:
<ul>
<li>A</li>
<li>C</li>
<li>B</li>
</ul>
I only want the Item C to reverse with Item B
3
Answers
Flexbox items can be displayed in an arbitrary order by using the
order
property:You can simply do it by using below 2 steps:
ul {display : flex; flex-direction: column;}
this will make list in column.As you want to change order of only second child you can use
li:nth-child(2) { order: 2;}
this will change order ofB
to third andC
to second.Note: Second Element of
li
which isB
will render at last as we have not assigned order to it.Thanks…
The order property in Flexbox grants the flexibility to arrange flex items in a customized visual order, irrespective of their original placement in the HTML structure.