rotateZ function
The rotateZ function sets rotation
around the Z-axis in three-dimensional space. It
is used together with the
transform
property. The property value is an angle in any
angle units.
A positive value rotates towards us, a negative
value rotates away from us. The rotation is
performed around the point specified by the
transform-origin
property.
Syntax
selector {
transform: rotateZ(angle);
}
Example
In this example, the block will rotate by
180 degrees around the Z-axis when
hovered. The
transition
property has been added to smooth
the rotation:
<div id="elem">lorem ipsum</div>
#elem {
border: 3px solid black;
width: 100px;
height: 50px;
transition: transform 3s linear;
}
#elem:hover {
transform: rotateZ(180deg);
}
:
Example
Let's change the rotation axis using the
transform-origin
property:
<div id="elem">lorem ipsum</div>
#elem {
border: 3px solid black;
width: 100px;
height: 50px;
transition: transform 3s linear;
transform-origin: center bottom;
}
#elem:hover {
transform: rotateZ(180deg);
}
: