CSS transform
CSS transform property translates, rotates, scales, or skews the box in a coordinate system.
1. transform (along 3-axes)
Example
transform:rotatex(45deg);
transform:rotatey(45deg);
transform:rotatez(45deg);
Try </>
The following are the following values of transform property.
rotate values
It can rotate the element along X, Y or Z axis. The value in the parentheses represents the value of angle.
For example, rotateX(45deg) means element should rotate 45 degree around X-axis.
rotateX()
rotateX() value rotates the element around x-axis.
Perspective property makes the projection of the box after rotating. The 3d tranformation is possible due to perspective property.
rotateY()
rotateY() rotates the element around y-axis.
rotateZ()
roateZ() rotates the element around z-axis.
translate(x,y) value
It translates the element along x and y axes. For example, translate(100px,100px) value translates the element 100px along x-axis and y-axis.
Example
<style>
.translate{
transform:translate(100px,100px);
}
</style>
Try </>
2. transform-style
There are two values of the transform-style. One is flat and the other one is preserve-3d. flat is the default value of tranform-style. preserve-3d preserves the 3d nature of the child element (box).
Remove the transform-style property to understand.
3. transform-origin
It specifies the reference point for the transformation. Normally, the transform-origin is at the center of the box. The value of transform-origin may be a keyword or numerical value.
Example
The transform-origin (reference point) of the first lightskyblue box is at the center of the box.
transform-origin:center;
The transform-origin of the second lightskyblue box is on the left side of the box.
transform-origin:left;
Try </>
There are many other values of the transform-origin such as right, top and bottom.
4. perspective property
It represents the projection of the box. The projection seems to be coming out of the page (3 dimensional). See the example to understand.
Perspective property is always used in the parent element (box). Remove or change the perspective property to understand.
Note: Always add -webkit- prefix to the transform, transition and animation type properties otherwise these properties don't work in safari.
A 3-D coordinate system consists of x, y and z-axes. X-axis is from left to right. Y-axis is from top to bottom. And Z-axis is perpendicular to this page.
Next Previous
Was this article helpful?