0 added
0 removed
Original
2026-01-01
Modified
2026-02-21
1
<p>The CSS Transform module for two-dimensional space provides several functions that allow you to transform elements by their coordinates:</p>
1
<p>The CSS Transform module for two-dimensional space provides several functions that allow you to transform elements by their coordinates:</p>
2
<ul><li>translate() - move an object by x and y coordinates</li>
2
<ul><li>translate() - move an object by x and y coordinates</li>
3
<li>rotate() - rotate an object relative to its upper-left corner</li>
3
<li>rotate() - rotate an object relative to its upper-left corner</li>
4
<li>scale() - scale an object</li>
4
<li>scale() - scale an object</li>
5
<li>skew() - skew an element in two-dimensional space. This function deforms the element</li>
5
<li>skew() - skew an element in two-dimensional space. This function deforms the element</li>
6
</ul><p>This course will cover all of these transformations and how they work. You should not be intimidated by the math in these lessons. You do not need to be a geometry wizard to do simple transformations.</p>
6
</ul><p>This course will cover all of these transformations and how they work. You should not be intimidated by the math in these lessons. You do not need to be a geometry wizard to do simple transformations.</p>
7
<h2>Coordinate system</h2>
7
<h2>Coordinate system</h2>
8
<p>We were taught in school that in a typical rectangular coordinate system, positive values on the x-axis go from the center to the right, and positive values on the y-axis go from the center up:</p>
8
<p>We were taught in school that in a typical rectangular coordinate system, positive values on the x-axis go from the center to the right, and positive values on the y-axis go from the center up:</p>
9
<p>The y-axis is inverted in browsers, and its positive values go down from the center. Remember it so you do not get confused when moving objects. You might have encountered this same feature when using the top property in the course<a>CSS: Positioning</a>:</p>
9
<p>The y-axis is inverted in browsers, and its positive values go down from the center. Remember it so you do not get confused when moving objects. You might have encountered this same feature when using the top property in the course<a>CSS: Positioning</a>:</p>
10
<h3>Reference point</h3>
10
<h3>Reference point</h3>
11
<p>An important feature of the CSS Transform module is the reference point from which the transformation takes place. This point is the upper-left corner of the object. This behavior is very similar to relative positioning, allowing you to use the features of absolute and relative positioning for the same element.</p>
11
<p>An important feature of the CSS Transform module is the reference point from which the transformation takes place. This point is the upper-left corner of the object. This behavior is very similar to relative positioning, allowing you to use the features of absolute and relative positioning for the same element.</p>
12
<p>Any HTML object on a page is a rectangle, regardless of its appearance. For example, create a circle and add a border with the outline property to see the lines. The point with coordinates (0, 0) is in the upper-left corner of the element:</p>
12
<p>Any HTML object on a page is a rectangle, regardless of its appearance. For example, create a circle and add a border with the outline property to see the lines. The point with coordinates (0, 0) is in the upper-left corner of the element:</p>
13
<h2>Moving an object</h2>
13
<h2>Moving an object</h2>
14
<p>To move the object along the x and y use the translate() function for the transform property.</p>
14
<p>To move the object along the x and y use the translate() function for the transform property.</p>
15
<p>It is an abbreviation of two functions:</p>
15
<p>It is an abbreviation of two functions:</p>
16
<ul><li>translateX()</li>
16
<ul><li>translateX()</li>
17
<li>translateY()</li>
17
<li>translateY()</li>
18
</ul><p>It allows you to move the object along the x and y-axes. The syntax of the translate function may differ:</p>
18
</ul><p>It allows you to move the object along the x and y-axes. The syntax of the translate function may differ:</p>
19
<ul><li>transform: translate(x, y)</li>
19
<ul><li>transform: translate(x, y)</li>
20
<li>transform: translateX(x) translateY(y)</li>
20
<li>transform: translateX(x) translateY(y)</li>
21
</ul><p>As you can see, the transform property can take on several functions simultaneously. It will help when we learn about more of the available features:</p>
21
</ul><p>As you can see, the transform property can take on several functions simultaneously. It will help when we learn about more of the available features:</p>
22
<p><strong>Note:</strong>the translate () is counted from the zero point of the object, not the page.</p>
22
<p><strong>Note:</strong>the translate () is counted from the zero point of the object, not the page.</p>
23
<p>Note the way elements overlap when using the transform property. An element with this property will be higher on the z-axis than the other elements, providing all other conditions are the same:</p>
23
<p>Note the way elements overlap when using the transform property. An element with this property will be higher on the z-axis than the other elements, providing all other conditions are the same:</p>
24
<h2>Relative VS Translate</h2>
24
<h2>Relative VS Translate</h2>
25
<p>During the lesson, you may wonder why you should use the translate() function when relative positioning and the top, right, bottom, and leftproperties have existed for a long time.</p>
25
<p>During the lesson, you may wonder why you should use the translate() function when relative positioning and the top, right, bottom, and leftproperties have existed for a long time.</p>
26
<p>Both approaches will give the same visual result, but, as usual, the devil is in the details. Two devils in this case:</p>
26
<p>Both approaches will give the same visual result, but, as usual, the devil is in the details. Two devils in this case:</p>
27
<ul><li>Using percentage values</li>
27
<ul><li>Using percentage values</li>
28
<li>Working with animations</li>
28
<li>Working with animations</li>
29
</ul><p>We will discuss the advantages of using the transform property in animation in the corresponding course. In short, browsers process motion animations using translate() faster than they use the positioning.</p>
29
</ul><p>We will discuss the advantages of using the transform property in animation in the corresponding course. In short, browsers process motion animations using translate() faster than they use the positioning.</p>
30
<p>In this case, we should know the difference regarding percentage values as soon as we start looking at transformations. Often, it is a forgotten point that leads to the waste of time in developing pages. In the example below, there are two squares.</p>
30
<p>In this case, we should know the difference regarding percentage values as soon as we start looking at transformations. Often, it is a forgotten point that leads to the waste of time in developing pages. In the example below, there are two squares.</p>
31
<p>We center them in their columns, after which we apply the following properties:</p>
31
<p>We center them in their columns, after which we apply the following properties:</p>
32
<ul><li>Number 1 square: translateX(50%)</li>
32
<ul><li>Number 1 square: translateX(50%)</li>
33
<li>Number 2 square: left: 50% with relative positioning</li>
33
<li>Number 2 square: left: 50% with relative positioning</li>
34
</ul><p>Assuming everything else is equal, both squares will have shifted by a different pixel number to the right from their original position. The feature consists of a frame of reference from which we count the relative sizes of these two properties.</p>
34
</ul><p>Assuming everything else is equal, both squares will have shifted by a different pixel number to the right from their original position. The feature consists of a frame of reference from which we count the relative sizes of these two properties.</p>
35
<p>For translateX(), this frame is the object itself. For a relatively positioned element, it is the container with it. In this case:</p>
35
<p>For translateX(), this frame is the object itself. For a relatively positioned element, it is the container with it. In this case:</p>
36
<ul><li>The number 1 square has been moved 100px / 2 = 50px to the right. 100px is the width of the square</li>
36
<ul><li>The number 1 square has been moved 100px / 2 = 50px to the right. 100px is the width of the square</li>
37
<li>The number 2 square has been moved 250px / 2 = 125px to the right. 250px is the size of the column where the square locates</li>
37
<li>The number 2 square has been moved 250px / 2 = 125px to the right. 250px is the size of the column where the square locates</li>
38
</ul><p>These modifications can be applied when positioning elements within a page. One of the most common tasks is to center the modal window. The positioning course had a similar<a>test</a>. It is hard to do accurate positioning using only absolute positioning. There are dozens of ways to do this, but using a combination of absolute positioning and translate() is the best option.</p>
38
</ul><p>These modifications can be applied when positioning elements within a page. One of the most common tasks is to center the modal window. The positioning course had a similar<a>test</a>. It is hard to do accurate positioning using only absolute positioning. There are dozens of ways to do this, but using a combination of absolute positioning and translate() is the best option.</p>
39
<h2>Additional assignment</h2>
39
<h2>Additional assignment</h2>
40
<p>Complete the test<a>Html: Modal Box Positioning</a>using absolute positioning and the translate() function.</p>
40
<p>Complete the test<a>Html: Modal Box Positioning</a>using absolute positioning and the translate() function.</p>