Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Scaling Elements3:12 with Guil Hernandez
One of the most common CSS transformations is scaling. You can increase or decrease the size of elements using scale functions like scaleX(), scaleY(), and scale().
- To apply a basic scale transformation, define a number that instructs the browser how large to scale an element.
- The default value for
- To make an element twice as large, write
2as the value:
scale()value evenly scales an element both vertically and horizontally.
scale()accepts a second number value inside the parenthesis.
- Two values let you individually scale the horizontal and vertical dimensions; write the scaling value for X first, followed by the scaling value for Y.
- When scaling an image, make sure that the original dimensions of the image is larger than the size at which you're scaling the image.
One of the most commonly used CSS transformations is scale.
You can increase or decrease the size of elements on the x or y axis
using scale functions like scale X and scale Y.
But most of the time, you're going to use the scale shorthand function
to evenly scale elements horizontally and vertically.
Like in this example.
So notice how the div scales twice as large when we hover over it.
So first I want to scale the size of my images on hover.
I'll go back to interactions .css and scroll down to the image
hover rule here and I'll change the transform function to the scale function.
Now applying a basic skill transformation is pretty straight forward.
Inside the parenthesis you write a number that instructs the browser how large
the scale and element So the default value for scale is 1.
Which is equivalent to no scaling.
Now if I want to make the images twice as large I can write 2 as the scale value.
So now the images zoom out from the center without affecting the rest of the content.
They scale evenly both vertically and horizontally.
So their width and height are now twice as big.
Now a value like 1.5 will make the images 1.5 times larger on hover.
The scale function also accepts a second number value inside the parentheses.
Now, two values let you individually scale the horizontal and vertical dimensions.
You write the scaling value for x first,
followed by a comma, and then the scaling value for y.
So let's make the y value 2.
So once we refresh the browser and hover over an image, the first value of
1.5 scales the width of the images, while the second value of 2 scales the height.
So now unhovered, the images are 1.5 whiter and twice as tall.
Now when you apply a scale to an image you should make sure that the original
dimensions of the images is written in your HTML
are larger than the size at which you're going to scale them.
That way you can safely scale your images while maintaining their quality.
Now the best and most visually appealing solution for
my image gallery Is one small scale value like 1.1.
Much better, so as you've seen, the spot at which an element scales and
rotates is the exact same center of the element by default.
In the next video you'll learn how to change the spot to scale or
rotate elements from other areas, like the top-left corner or bottom-right corners.
You need to sign up for Treehouse in order to download course files.Sign up