2D Transform with CSS3
With CSS3, we can apply effects such as rotate (rotate), scale (scaling), skew (tilt), translate (shift) to html elements .
For this, the transform property and the type of transformation to be applied are used.
Note: For older versions of browsers, the -webkit-, -moz-, -o- and -ms- prefixes must be used. This was written in the first examples on this page, while it was omitted in the others.
You can see and examine the working versions of the examples in the Subject Examples section.
Rotate - Rotate Objects
#box1{
transform: rotate(20deg);
-ms-transform: rotate(20deg); /* IE 9 */
-webkit-transform: rotate(20deg); /* Safari */
}
We can make it rotate clockwise by using a negative value.
Skew - Skew Objects
Using SkewX function skews in x axis, skewY skews in y-axis, skew in both x and y axis.
The number of degrees of inclination to be applied is indicated in parentheses.
transform: skewX(30deg);
-ms-transform: skewX(30deg); /* IE 9 */
-webkit-transform: skewX(30deg); /* Safari */
transform: skewY(30deg);
-ms-transform: skewY(30deg); /* IE 9 */
-webkit-transform: skewY(30deg); /* Safari */
transform: skew(30deg);
-ms-transform: skew(30deg); /* IE 9 */
-webkit-transform: skew(30deg, 10deg); /* Safari */
Scale - Scaling Objects
With the scale function, we can show objects larger or smaller than they are. The number of times the width and height of the function will be increased is written in the parentheses. Values between 0 and 1 make the object appear smaller than it is.
When we apply this effect to objects, the elements within that object will also grow.
transform: scale(1.5,1.5);
Translate - Changing Position of Objects
It was possible with the position and top-right-bottom-left properties to make the html elements appear in a different place than they should be. We can do this more easily with the translate function.
Write how much to shift in the x and y axis, respectively, in parentheses. Negative values enable scrolling left or top.
transform: translate(50px,75px);
Applying Multiple Transformations Using the Matrix Function
Transformation can be applied by specifying horizontal magnification, vertical skew (skewY), horizontal skew (skewX), vertical magnification, horizontal scrolling and vertical scrolling amounts in a single line, respectively .
Here's how we can show the usage:
matrix(scaleX(),skewY(),skewX(),scaleY(),translateX(),translateY());
Sample:
transform: matrix(1, -0.3, 0, 1, 0, 0);
css objects rotate, tilt, enlarge, css3 transform property, transform html elements with css3, shift objects away from where they should be
EXERCISES
Css transform - rotate example
|
Try It
|
Css transform - skew tutorial
|
Try It
|
Css transform - scale example
|
Try It
|
Css transform - translate tutorial
|
Try It
|
Applying all transformations in one line using Matrix function
|
Try It
|
Read 868 times.