When working with this straightforward HTML structure:
<div id="base">
<div id="clip">
<div id="image">
</div>
</div>
</div>
You can style it using the following CSS:
div {
overflow: hidden;
-webkit-transform-style: preserve-3d;
}
#base {
position: absolute;
top: 50px;
left: 50px;
width: 200px;
height: 200px;
transition: all 0.3s;
}
#clip {
width: 290px;
height: 290px;
-webkit-transform: rotateZ(-45deg);
-webkit-transform-origin: 0px 0px;
}
#image {
width: 200px;
height: 200px;
-webkit-transform: rotateZ(45deg);
-webkit-transform-origin: 0px 0px;
background-image: linear-gradient(0deg, red, blue);
}
#base:hover {
-webkit-transform: rotate3d(1,1,0,-45deg);
-webkit-transform-origin: center center;
}
Using a base square div as the starting point, you rotate an inner div by 45 degrees to create a clipping effect. Inside the clipped area, another div called image is set at a counter rotation angle of 45 degrees to maintain horizontal alignment for the image. When hovering over the base div, a 3D rotation effect is applied around the diagonal axis.