I'm trying to transform my div like the green box.

I want to get 3D transform, not mask :

I find a way with this generator but the css code doesn't work on my fiddle:
/*transform css3*/
#screen {
transform: scale(1.0) scaleZ(1.0) rotateX(-16deg);
transform-origin: 0% 0%;
perspective: 450;
perspective-origin: 100% 50%;
}

body {
height:100%;
padding:0;
margin:0;
}
#mask {
background:url(https://i.sstatic.net/cBK0O.png) no-repeat;
background-size:350px;
height:200px;
position:relative;
}
#screen:hover {
background:url(https://www.actugaming.net/wp-content/uploads/2018/06/Assassins-Creed-Odyssey_Leak_06-10-18_015-1.jpg);
background-size:100%;
}
#screen {
position:absolute;
bottom:38px;
background:red;
opacity:0.6;
}
#screen {
left:70px;
width:240px;
height:calc(240px * 9 / 16); /*keep 16/9 !*/
}
/*transform css3*/
#screen {
transform: scale(1.0) scaleZ(1.0) rotateX(-16deg);
transform-origin: 0% 0%;
perspective: 450;
perspective-origin: 100% 50%;
}
<div id="mask">
<div id="screen"></div>
</div>
If you want that shape, you could use clip-path instead of using transform. This gives you a great amount of control over the shape you get. Here's a good tool to help you out: https://bennettfeely.com/clippy/
Using transform, you can skew the image to achieve a 3d effect on the background/div content.
#screen:hover {
background: url(https://www.actugaming.net/wp-content/uploads/2018/06/Assassins-Creed-Odyssey_Leak_06-10-18_015-1.jpg);
background-size: 100%;
}
#screen {
position: absolute;
background: red;
opacity: 0.6;
left: 70px;
width: 240px;
height: calc(240px * 9 / 16);
/*keep 16/9 !*/
transform-origin: bottom right;
-ms-transform: skew(20deg, 0deg);
-webkit-transform: skew(20deg, 0deg);
transform: skew(20deg, 0deg);
}
<div id="screen"></div>
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