transform property in CSS- part 2

Note: This is the second part of a 4 part series dedicated to the transform property of CSS.

In this part, we’ll understand the value ‘scale’ of the transform property but if you want to jump to any other function of the transform property, be my gues…


This content originally appeared on DEV Community and was authored by Rajat Gupta

Note: This is the second part of a 4 part series dedicated to the transform property of CSS.

In this part, we'll understand the value 'scale' of the transform property but if you want to jump to any other function of the transform property, be my guest and click on the links provided below:

part 1: rotate

part 2: scale

part 3: translate (yet to be published)

part 4: skew (yet to be published)

Let's get started:

Let's see what MDN has to say: The scale() CSS function defines a transformation that resizes an element on the 2D plane. Because the amount of scaling is defined by a vector, it can resize the horizontal and vertical dimensions at different scales. Its result is a data type.

The scale() is used to scale (increase and decrease both) the length of an element across the X, Y, and Z-axis but since here we are dealing with 2D objects, I'll show you how to scale elements in the x and y direction using this property.

Let's make a red div (or box) to understand the scale() in transform:

 div{
            height: 100px;
            width: 100px;
            background-color: red;
            border: 1px solid black;
        }

1.PNG

(1) In the below example we applied (transform: scale(3)) on the div and length of the box across both x and y-axis has become 3 times the previous length.

div{
            height: 100px;
            width: 100px;
            background-color: red;
            border: 1px solid black;
            transform: scale(3);
        }

2.PNG

(2) Instead of giving only one value (transform: scale(3)), we can provide two values one for the x-axis and another one for the y-axis. see the example below:

div{
            height: 100px;
            width: 100px;
            background-color: red;
            border: 1px solid black;
            transform: scale(4, 0.5);
        }

3.PNG
☝️Here, the length of the box along the x-axis has become 4 times and it has halved along the y-axis.

(3) If we want to scale length only across one direction we can use either scaleX or scaleY (depending on the direction we want to scale)

div{
            height: 100px;
            width: 100px;
            background-color: red;
            border: 1px solid black;
            transform: scaleX(4)
        }

4.PNG

☝️ here the length along the x-axis has become 4 times the previous length. However, there is no change across the y-axis.

Frankly, the scale() function is quite straightforward but if you still have any doubt, feel free to ask in the comments section and do not forget to check other functions of transform (link at the top).

I write one article every day related to web development (yes, every single f*cking day). Follow me here if you are learning the same..

my Twitter handle: @therajatg

If you are the Linkedin type, let's connect: https://www.linkedin.com/in/therajatg/

Have an awesome day ahead 😀!


This content originally appeared on DEV Community and was authored by Rajat Gupta


Print Share Comment Cite Upload Translate Updates
APA

Rajat Gupta | Sciencx (2022-02-04T18:55:48+00:00) transform property in CSS- part 2. Retrieved from https://www.scien.cx/2022/02/04/transform-property-in-css-part-2/

MLA
" » transform property in CSS- part 2." Rajat Gupta | Sciencx - Friday February 4, 2022, https://www.scien.cx/2022/02/04/transform-property-in-css-part-2/
HARVARD
Rajat Gupta | Sciencx Friday February 4, 2022 » transform property in CSS- part 2., viewed ,<https://www.scien.cx/2022/02/04/transform-property-in-css-part-2/>
VANCOUVER
Rajat Gupta | Sciencx - » transform property in CSS- part 2. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/02/04/transform-property-in-css-part-2/
CHICAGO
" » transform property in CSS- part 2." Rajat Gupta | Sciencx - Accessed . https://www.scien.cx/2022/02/04/transform-property-in-css-part-2/
IEEE
" » transform property in CSS- part 2." Rajat Gupta | Sciencx [Online]. Available: https://www.scien.cx/2022/02/04/transform-property-in-css-part-2/. [Accessed: ]
rf:citation
» transform property in CSS- part 2 | Rajat Gupta | Sciencx | https://www.scien.cx/2022/02/04/transform-property-in-css-part-2/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.