With the transform property, you can manipulate an element's angle, size, shape, position, and many others properties. The syntax for transform is simple, and looks like this:
CSS
transform: function(values);
You simply indicate the function you want to apply, pass in some values and let the browser do the work.
2D Translate
Perhaps the easiest function to demonstrate is the translate function.
Acting similar to using position: relative and giving it a left and top value, it moves the element horizontally and vertically. The units for translate is a length.
You can scale up and down the apparent size of an element using the scale function. The default value is1 where any smaller value makes the element appear smaller, and any value bigger makes the element appear larger.
Notice how two values were passed to scale? The first value is for the x and the second is for the y.
The width of the box was made to be 75% of the original width, and the height125% of the original height.
2D Skew
Skewing an element lets you distort an element by adjusting the tilt on the horizontal and/or vertical axis. The value for the skew function is in degrees.
Skewing a box 5 degrees in the X-axis and 10 degrees in the Y-axis.
HTML
CSS
CSS
transform: scale(xdeg, ydeg)
Transform Origin
The origin of every transform you perform will be, by default, at the very center of the element. This means that the element will be rotated, scaled, and skewed around the center of the element.
That is why when you try, for example, to rotate a box, it will rotate about the very center. If you wanted to rotate it around one of its edges, well, you're in luck.
Using transform-origin, you can set the origin to wherever you want it to be. The default value is:
CSS
transform-origin: 50%50%;
Multiple Transforms
In the event that one transform doesn't satisfy you, you can easily apply multiple at once by combining them. This is done by separating them with a space. The order of the transforms matter, so the order in which you apply them matters. The order of the transforms is important.
All you need to do is supply the transform property with your list of functions, and the browser will do the rest. Let's say you wanted to skew and scale a box:
CSS transforms are a powerful way to manipulate the appearance of an element. Use them to create interesting effects, or just to make your page look a little better.