In last 5 articles of this web development series, we learned and understood the concept of CSS Grids which helps to create responsive layouts for web pages in very few lines of CSS. Now moving forward, we are going to see about styling various elements using transformations and animations. So let's begin...
That's all for today. In the next article, we will see remaining 2D transformation properties and then we will move to 3D properties.
CSS Transforms
CSS translations allow us to translate, rotate, scale and skew elements created in HTML using CSS. These transformations may change shape, position, size, and orientation of element. CSS transforms is mainly divided into 2D and 3D. 3D transforms make changes such that we feel them in 3 dimensions.
CSS 2D Transformations
Following are some of the commonly used 2D transformations:
- translate()
- rotate()
- scale()
- skewX()
- skewY()
- matrix()
The translate() method
This method changes the position of the element from its current position. The change in position is according to parameters given to translate(), where the first parameter represents a shift in X while the second parameter represents a shift in the Y direction.
The given example will shift div to right by 40px and down by 100px.
The rotate() method
Rotates the element by clockwise by given number of degrees. For anti-clockwise rotation, use a negative sign for degrees.
div {
-ms-transform: rotate(-30deg); /* IE */
-webkit-transform: rotate(-30deg); /* Safari */
transform: rotate(-30deg);
}
The scale() method
The scale() method changes the size of the element according to the given parameters. The first parameter indicates a change in width while second indicates a change in height. Positive values indicate increase while negative values cause a decrease in size.div {
-ms-transform: scale(4, -3); /* IE */
-webkit-transform: scale(4, -3); /* Safari */
transform: scale(4, -3);
}
Till then #keepCoding.
Comments
Post a Comment