Is there a way to correctly detect the last child after rearranging divs using flex order? Even though I have set the order in the CSS, it is still recognizing the last child based on the DOM tree. Since the items are dynamic, we can't rely on nth-child. How can I target the actual last child when they have been reordered with flex order? There may be multiple items that need to appear at the top. I'm looking for a solution using either CSS or JavaScript.
<div class="mainWrap">
<div class="item">first</div>
<div class="item">second</div>
<div class="item orderFirst">third</div>
<div class="item">fourth</div>
<div class="item orderFirst">fifth</div>
<div class="item">Six</div>
<div class="item orderFirst">Seven</div>
</div>
<style>
.mainWrap {display:flex; flex-direction: column;}
.mainWrap .item {order:2; border-bottom:1px solid #ccc}
.mainWrap .item:last-of-type {border-bottom:none;}
.mainWrap .item.orderFirst {order:1;}
</style>