Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make 3 elements overlap each other with CSS

Tags:

html

css

z-index

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:

enter image description here

Is it possible with CSS?

like image 445
Jared Avatar asked Oct 30 '14 02:10

Jared


People also ask

How do you make overlapping elements in 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.

Which CSS style property controls how elements overlap each other?

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).


1 Answers

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: Impossible Z-index

Demo with borders
Demo without borders

like image 107
JimmyRare Avatar answered Oct 29 '22 16:10

JimmyRare