Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Start a free Basic trial
to watch this video
It's common to use multiple transforms at once. The 'transform' property can accept as many functions as needed, so you can use and combine them any way you want.
Resources
Video review
- It's common to use multiple transforms at once.
- For example:
transform: rotate(-5deg) scale(1.1);
- Define only one transform declaration in a rule, otherwise the bottom-most declaration will override the transforms above.
-
0:00
The transform property can accept as many functions as needed.
-
0:04
So you can use and combine them anyway you want.
-
0:08
It's common to use multiple transforms at once.
-
0:12
For example, you might want to rotate and
-
0:14
scale the size of an element at the same time.
-
0:17
Earlier we applied a small rotation to the top row of images on hover.
-
0:23
I really liked how that looked, so I'm going to add the rotation back in.
-
0:27
So I'll go back to interactions.css.
-
0:31
And in my image hover rule here,
-
0:35
I'm going to replace the translate function with the rotate function.
-
0:40
And I'll set the value to -5deg.
-
0:46
All right, so let's make this transformation a little
-
0:50
more amusing by combining rotate with a scale transform.
-
0:56
To do this I can simply add the scale function anywhere in the transform value.
-
1:01
And it will apply it to the image at the same time it applies the rotation.
-
1:06
So, right after the rotate function, I'll add the scale function and
-
1:10
set the value to 1.1.
-
1:14
So the images now rotate negative five degrees counterclockwise,
-
1:20
while they scale 1.1 times their size.
-
1:22
Now we can add more transforms if we need them.
-
1:25
So for example, back in my hover rule I'm going to add the translateY
-
1:32
function and set the value to negative 20 pixels.
-
1:39
Once we hover over an image, we can see that the images rotate,
-
1:43
scale, and translate up all at the same time.
-
1:48
Keep in mind that you can only define one transform declaration in a rule.
-
1:53
Otherwise, the bottom most declaration will override everything above it.
-
1:58
And this is a common mistake developers make when writing CSS transforms.
-
2:02
So, for example, later on I may want to add a skew transformation to these images.
-
2:08
So instead of writing the skew function here in the original list of values,
-
2:14
I might add it to the bottom of the rule like this.
-
2:24
So now the only transform we see applied is the skew.
-
2:29
Because the new transform declaration overrides the one written above it.
-
2:36
Now, this is just a simple example.
-
2:38
A small mistake like this is pretty easy to spot in one CSS rule, but sometimes you
-
2:44
may target the same element further down in your CSS and try to apply a transform.
-
2:50
This is how you'd most likely run into this problem.
-
2:52
So for instance, if I scroll all the way down to the bottom of my style sheet and
-
2:58
say img:hover and apply the skew transformation here in this rule,
-
3:03
once we refresh the browser once again the rotate and
-
3:07
scale transforms are gone on hover, they've been overwritten by the new rule.
-
3:20
Now, I really like the way the images move when we combined rotate and scale.
-
3:25
So, I'm going to stick with these two functions moving forward.
You need to sign up for Treehouse in order to download course files.
Sign up