I would like to create a paradoxical effect via the z-index
CSS property.
In my code I have five circles, like in the image below, and they are all absolutely positioned with no defined z-index
. Therefore, by default, every circle overlaps the previous one.
Right now, circle 5 overlaps circle 1 (left image). The paradox I'd like to achieve is to have, at the same time, circle 1 under the circle 2 and on top of circle 5 (as in the right image).
http://paradox.schramek.cz/1.jpg
Here's my code
Markup:
<div class="item i1">1</div>
<div class="item i2">2</div>
<div class="item i3">3</div>
<div class="item i4">4</div>
<div class="item i5">5</div>
CSS
.item {
width: 50px;
height: 50px;
line-height: 50px;
border: 1px solid red;
background: silver;
border-radius: 50%;
text-align: center;
}
.i1 { position: absolute; top: 30px; left: 0px; }
.i2 { position: absolute; top: 0px; left: 35px; }
.i3 { position: absolute; top: 30px; left: 65px; }
.i4 { position: absolute; top: 70px; left: 50px; }
.i5 { position: absolute; top: 70px; left: 15px; }
A live example is also available at http://jsfiddle.net/Kx2k5/.
I tried a lot of techniques with stacking orders, stacking context and so on. I read some articles about these techniques, but no success. How can I solve this?
JS Fiddle
HTML
CSS
Here's my go at it.
I also use a pseudo element positioned on top of the first circle, but rather than using clip, I keep its background transparent and just give it an inset box-shadow that matches the background color of the circles (silver) as well as a red border to cover the bottom right sides of the circle's border.
Demo
CSS (that is different from starting point)
Final product
Sadly the following is just a theoretical answer, as for some reason I can't get
-webkit-transform-style: preserve-3d;
to work (have to be making some obvious mistake, but can't seem to figure it out). Either way, after reading your question I - as with every paradox - wondered why it's only an apparent impossibility, rather than a real one. Another few seconds me realize that in real life the leaves are rotated a bit, thus allowing such a thing to exist. So then I wanted to concoct a simple demonstration of the technique, but without the previous property that's impossible (it gets drawn to the flat parent layer). Either way, here is the base code none the lessAnd the css:
And you can find the full code here.
My attempt also using
clip
. The idea was to have half and half for thediv
. That way settingz-index
would work.So you can set the top part to
z-index: -1
and the bottom toz-index: 1
.Outcome:
DEMO HERE
Note: Tested on IE 10+, FF 26+,Chrome 33+ and Safari 5.1.7+.
Here's my attempt: http://jsfiddle.net/Kx2k5/1/
(successfully tested on
Fx27
,Ch33
,IE9
,Sf5.1.10
andOp19
)CSS
Basically I've overlapped an
:after
pseudoelement over the first circle (with some properties inherited), then I've clipped it withclip()
property, so I only make its bottom section visible (where circle#1
overlaps the circle#5
).For the CSS properties I've used here, this example should be working even on IE8 (
box-sizing
,clip()
,inherit
, and pseudoelements are supported there)Screenshot of resulting effect
JS Fiddle LIVE DEMO
Works on IE8 too.
HTML
CSS