I have the following use case that I want to achieve in HTML format
I've two div element with background red and blue. The blue div is added later of which a part overlaped with red div. I have the option of "send to back" which sends the selected div to back of other div. If I apply this to blue div and select blue div it should look like below image

Mostly I'm trying to use the Arrange --> Order --> Send to back functions for Google Presentation
I tried z-index without success. I can use background-gradient with the overlapping part of the blue div transparent , but this will cause some calculations that I want to avoid.
How to achieve this in HTML?
Any help is appreciated.
Note. All div elements are placed in position: absolute
Update: the red div is above the blue div , since its z-index higher than the blue div . When a red div selected, it should look like this (with a border selected).

Now, if I select a blue div , the part of it that overlaps with the red div does not appear (obviously, since its z-index smaller), but I want its border appear when I select .it.
source share