CSS transforms allow you to apply 2D effects to elements like moving, rotating, scaling, or skewing them without changing the layout around them.
translate(x, y): Moves an element along the X and Y axesrotate(angle): Rotates the element by a specified degreescale(x, y): Scales an element up or downskew(x, y): Skews the element by given anglesmatrix(a, b, c, d, e, f): Combines all transforms in one functionTranslate:
transform: translate(50px, 20px);Rotate:
transform: rotate(45deg);Scale:
transform: scale(1.5);Skew:
transform: skewX(20deg);Matrix:
transform: matrix(1, 0.3, 0.3, 1, 0, 0);transition for interactive effectstransform instead of manipulating position or margin for performanceperspective: Defines the distance between the user and the Z=0 plane.rotateX(deg): Rotates an element around the X-axis.rotateY(deg): Rotates an element around the Y-axis.rotateZ(deg): Rotates an element around the Z-axis (similar to 2D rotate).translateZ(px): Moves the element along the Z-axis toward or away from the user.transform-style: preserve-3d: Allows child elements to preserve 3D transforms.Perspective Container:
parent {
perspective: 500px;
}Rotate X:
transform: rotateX(45deg);Rotate Y:
transform: rotateY(45deg);Rotate Z:
transform: rotateZ(45deg);Translate Z:
transform: translateZ(50px);Preserve 3D:
parent {
perspective: 500px;
}
.container {
transform-style: preserve-3d;
transform: rotateY(30deg);
}
.child {
transform: translateZ(30px);
}Try creating a card that rotates and scales on hover using transform.
Here is the code to the prompt. Click to download
Ask the AI if you need help understanding or want to dive deeper in any topic