The only way, as you have in the case of the sample, is to actually have a different division of the DIV over another - if this happens after it in the DOM. So your simple answer is that any div is on top of another div if it appears after it in the DOM tree. Please provide a more illustrative example if this is not enough.
You can illustrate that this works by trying to add a positive margin to DIV1. You will notice that it hits DIV2 down. DIV2, however, when a given negative margin will be a βlayerβ over DIV1. In your scenario using fields and sections without a z-index or other positioning methods, it is not possible for DIV1 to overlap DIV2.
EDIT based on comments:
The process of figuring out if two elements occupy the same space is a different game. The general run of your method would be to get the coordinate position for your anchor and get its width and height. Then scroll through all the divs and see if the snap position overlaps any of its coordinates. If it overlaps multiple divs, take the latter in the DOM, as it will be on top of the other.
Please do not force me to write sample code. :)
Adam terlson
source share