According to the specification, elements are typically drawn "in tree order" for in-flow, non-positioned elements of similar block level or float status and identical z-index. This means that elements declared last in the HTML markup appear on top. But what if we need to reverse this order for specific children within a container?
For example, imagine having multiple overlapping floated divs within a parent div:
__________________________________
| _________________________ |
| | samant| allis| rachael |... |
| |_______|______|_________|... |
|_________________________________|
And we actually want it to be displayed like this:
__________________________________
| _________________________ |
| | samantha | lison | chael |... |
| |__________|______|_______|... |
|_________________________________|
You can view an example here.
If CSS alone does not offer a solution for achieving this effect, what would be the most efficient and secure way to implement this functionality using JavaScript for arbitrary child elements?
Similar questions have been asked before regarding reversing z-index based on page render order, such as this one and this one.