How can you reverse the order of only certain div’s children elements with pure CSS?
For example:
I want
<div id="parent">
<a>A</a>
<a>B</a>
<a>C</a>
<a>D</a>
<div id="sub-child">
<a>X</a>
<a>Y</a>
<a>Z</a>
</div>
</div>
to be displayed as:
D
C
B
A
X
Y
Z
I tried:
#parent {
display:flex;
flex-direction: column-reverse;
}
However, It is reversing everything inside parent (Not giving desired result)
>Solution :
- apply
display: flexon both#parentand#sub-child; - give
flex-direction: column-reversefor the#parentandflex-direction: columnfor#sub-child; - use a negative
orderfor#sub-childso to keep that node at the bottom
#parent {
display: flex;
flex-direction: column-reverse;
}
#sub-child {
order: -1;
display: flex;
flex-direction: column;
}
<div id="parent">
<a>A</a>
<a>B</a>
<a>C</a>
<a>D</a>
<div id="sub-child">
<a>X</a>
<a>Y</a>
<a>Z</a>
</div>
</div>