Need help with Order for display flex

Order is used to change to position of the child elements in a flex box. i tried the same but its not quite the same. there is a main div location-jokes container which has display:flex and flex-direction:column properties . Now i wanted to reverse the order of childs so i used following order to change the position, the child position is changed but the grandchildren position is affected by this, how to fix it, so only child position is moved ? i have attached the code and ss for better understanding
.location-jokes :first-child {
order: 2;
margin: 1rem 0;

}

.location-jokes :nth-child(2) {
order: 1;
margin: 1rem 0;

}
.location-jokes :first-child {
order: 2;
margin: 1rem 0;

}

.location-jokes :nth-child(2) {
order: 1;
margin: 1rem 0;

}
https://codepen.io/avinash-tallapaneni/pen/ExRomwX
3 Replies
Avinash
AvinashOP2y ago
if you look at the outline after order is applied grandchildrens are getting affected
13eck
13eck2y ago
It's affecting the grandchildren because your CSS tells it to. You're using the Descendant combinator selector:
.location-jokes :first-child {

}
.location-jokes :first-child {

}
Note the space ( ) between the two identifiers. What you want is the Child combinator:
.location-jokes > :first-child {

}
.location-jokes > :first-child {

}
Note the >: that says "only direct children". https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors#combinators
Avinash
AvinashOP2y ago
oh. it worked jollykevin
Want results from more Discord servers?
Add your server