I was wondering if a solution exists in pure CSS to color the intersection between two divs.
For exemple, if I have two divs, with the same class like this:
<div class="orange_square"></div>
<div class="blue_square"></div>
They are placed on the page so they so they overlap, like this:

I want the intersection of these two divs to be colored in red, and this in CSS only. I was wondering if something like this existed:
.orange_square {
   background-color:orange;
}
.blue_square {
   background-color:blue;
}
.orange_square [overlap_operator?] .blue_square {
   background-color:red;
}
Is that possible?
(sorry)
Although there isn't a way to automatically calculate & define define such a area purely in CSS, if you know the dimensions of the two 'parent' divs, you can hard code it without adding additional DOM clutter, which is going to be as close as you can get just using CSS and div elements:
HTML
<div></div>
<div></div>
CSS
div {
    position:absolute;
    height:100px;
    width:100px;
}
div:first-of-type {
    background:orange;
}
div:last-of-type:before {
    content:'';
    height:33px;
    width:33px;
    display:block;
    position:absolute;
    background:red;
}
div:last-of-type {
    background:lightblue;
    top:75px;
    left:75px;
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With