I have 3 elements:
<div class="foo"></div>
<div class="bar"></div>
<div class="foobar"></div>
I want .foo
to overlap .bar
, .bar
to overlap .foobar
, .foobar
to overlap .foo
.
Like this:
Is it possible with CSS?
Using CSS Z-Index property developer can stack elements onto one another. Z-Index can have a positive or a negative value. NOTE − If elements that overlap do not have z-index specified then that element will show up that is mentioned last in document.
The z-index property in CSS controls the vertical stacking order of elements that overlap. As in, which one appears as if it is physically closer to you. z-index only affects elements that have a position value other than static (the default).
There is no normal solution to this problem, however you can do some tricks to make the illusion.
If you create a fake-foobar
inside of .bar
like this markup, you can then position .fake-foobar
inside .bar
so that it looks like the corner of .foobar
.
<div class="box foo"></div>
<div class="box bar">
<div class="box fake-foobar"></div>
</div>
<div class="box foobar"></div>
Here is an image showing you the trick:
Demo with borders
Demo without borders
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