If I have perspective
applied to <body>
, is there any way to override the depth sorting created by transform3d?
I have a element with position: sticky
, and then a div which has some child elements given translations (towards the viewer) on the Z axis. These elements always appear in front of the sticky element. Is there any way to supersede the Z transformation?
The perspective needs to be applied to body to produce parallax effects from scrolling.
(minimal example here, strangely this example seems to work in Chrome, altho I know that it shouldn't, not according to spec at least!)
https://codepen.io/ollyskinner/pen/JjdXVam
Edit: As suggested by Paulie_D, snippet of the same example
html, body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
body {
overflow-x:hidden;
overflow-y:auto;
perspective: 100px;
perspective-origin: left;
}
.wrapper {
position: relative;
height: 150vh;
transform-style: preserve-3d;
}
.el {
padding: 10px;
}
.el.sticky {
position: sticky;
top: 0;
width: 100px;
height: 50px;
background: grey;
z-index: 100;
}
.el.preserve3d {
background-color: aqua;
transform-style: preserve-3d;
width: 300px;
}
.el.transformed {
position: relative;
width: 200px;
height: 50vh;
background-color: rgba(120,120,0,0.5);
border: 1px solid red;
transform: translate3d(0,0,10px) rotateY(15deg) scale(0.9);
}
<div class="wrapper">
<div class="el sticky">sticky element</div>
<div class="el preserve3d">
<div class="el transformed">content</div>
</div>
</div>