By modifying the coordinate space, CSS transforms allow to change the position of the affected content without disrupting the normal flow. They are implemented using a set of CSS properties that let you apply affine linear transformations to HTML elements. These transformations include rotation, skewing, scaling, and translation both in the plane and in the 3D space.
CSS transforms properties
- Specifies the position of the origin. By default it is at the top left corner of the element and can be moved. It is used by several transforms, like rotations, scaling or skewing, that need a specific point as parameter.
- Specifies the transforms to apply to the element. It is a space separated list of transform, which are applied one after the other, like requested by the composition operation.
This example creates an iframe that lets you use Google's home page, rotated 90 degrees about its bottom-left corner.
<div style="-moz-transform: rotate(90deg); -moz-transform-origin: bottom left;"> <iframe src="http://no.google.anymore/" width="500" height="600"></iframe> </div>
Example: Skewing and translating
This example creates an iframe that lets you use Google's home page, skewed by 10 degrees on the X axis.
<div style="-moz-transform: skewx(10deg) translatex(150px); -moz-transform-origin: bottom left;"> <iframe src="http://no.google.anymore/" width="600" height="500"></iframe> </div>
3D specific CSS properties
Performing CSS properties in the space is a little bit more complex. You have to start by configuring the 3D space by giving it a perspective, then you have to configure how your 2D elements will behave in that space.
Setting up a perspective
The first element to set is the perspective. The perspective is what gives the 3D impression. The farther from the viewer the elements are, the smaller there are.
How quick they shrink is defined by the
property. The smaller its value is, the deeper the perspective is.
| || || || |
The second element to configure is the position of the viewer, with the
property. By default, the perspective is centered on the viewer, which is not always adequate.
| || || |
Once you have done this, you can work on the element in the 3D space.
2D elements in the 3D space
-moz-transform, including CSS transform functions
- Using deviceorientation in 3D Transforms
|HTML||Audio/Video Canvas WebGL SVG MathML WebForms AppCache Microformats SemanticTags|
|CSS||NewSelectors Typography Visual Effects|