Transforms Flashcards

1
Q

What is the transform CSS property used for?

A

The transform CSS property is used to modify the position, scale, and rotation of an element, either in 2D or 3D space.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the syntax and possible values for the transform CSS property?

A

The syntax for the transform CSS property is

transform: function(value);

Possible values include functions such as translate, scale, rotate, skew, and matrix, each with their respective values.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How can you apply multiple transforms to an element?

A

You can apply multiple transforms by chaining the functions together, separated by spaces, like this:

transform: function1(value) function2(value);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the common 1-dimensional transforms in CSS?

A

The common 1-dimensional transforms in CSS are translateX(), translateY(), scaleX(), scaleY(), and skewX(), skewY().

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are the main 3-dimensional transforms in CSS?

A

The main 3-dimensional transforms in CSS are translate3d(x, y, z), scale3d(x, y, z), rotateX(angle), rotateY(angle), rotateZ(angle), and matrix3d().

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the main types of CSS transform functions?

A

The main types of CSS transforms are translation, scaling, rotation, skewing, and matrix transformations.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does the translate() CSS transform function do?

A

The translation transform moves an element from its current position along the X, Y, or Z axis without affecting the layout of surrounding elements.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the syntaxes for translate() CSS transform functions?

A

The syntaxes for translation functions in CSS are: translate(tx, ty), translateX(tx), translateY(ty), and translate3d(tx, ty, z).

Values:

  • tx - Is a <length> or <percentage> representing the abscissa of the translating vector.
  • ty - Is a <length> or <percentage> representing the ordinate of the translating vector.
  • tz - Is a <length> representing the z component of the translating vector. It can’t be a <percentage> value; in that case the property containing the transform is considered invalid.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What does the scale() CSS transform do?

A

The scaling transform resizes an element’s width and height by a specified factor without affecting the layout of surrounding elements.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are the syntaxes for scale() CSS transform functions?

A

The syntaxes for scaling functions in CSS are: scale(sx, sy), scaleX(sx), scaleY(sy), and scale3d(sx, sy, sz).

Argument values

  • sx - Is a <number> representing the abscissa of the scaling vector.
  • sy - Is a <number> representing the ordinate of the scaling vector. If not defined, its default value is sx, resulting in a uniform scaling that preserves the element’s aspect ratio.
  • sz - Is a <number> representing the z-component of the scaling vector.

NOTE: scale, scaleX and scaleY also accepts <percentage> as argument values.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What does the rotate() CSS transform function do?

A

The rotation transform rotates an element around a specified axis without affecting the layout of surrounding elements.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

List all rotate CSS transform functions

A

rotate(angle), rotateX(angle), rotateY(angle), rotateZ(angle), and rotate3d(x, y, z, angle).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the syntax of the rotate() CSS transform function?

A
rotate(angle);

Values

  • angle - Is an <angle> representing the angle of the rotation. The direction of rotation depends on the writing direction. In a left-to-right context, a positive angle denotes a clockwise rotation, a negative angle a counter-clockwise one. In a right-to-left context, a positive angle denotes a counter-clockwise rotation, a negative angle a clockwise one.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What does the skew() CSS transform function do?

A

The skew() CSS function defines a transformation that skews an element on the 2D plane. Its result is a <transform-function> data type.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the syntax of the skew() CSS transform function?

A

Syntax

skew(ax)
skew(ax, ay)

Values

  • ax - Is an <angle> representing the angle to use to distort the element along the x-axis (or abscissa).
  • ay - Is an <angle> representing the angle to use to distort the element along the y-axis (or ordinate). If not defined, its default value is 0, resulting in a purely horizontal skewing.</angle>
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What does the translate CSS property do?

A

The translate CSS property allows you to specify translation transforms individually and independently of the transform property.

This maps better to typical user interface usage, and saves having to remember the exact order of transform functions to specify in the transform value.

17
Q

What is the syntax of the translate CSS property?

A

Syntax

/* Keyword values */
translate: none;

/* Single values */
translate: 100px;
translate: 50%;

/* Two values */
translate: 100px 200px;
translate: 50% 105px;

/* Three values */
translate: 50% 105px 5rem;

Values

  • Single <length-percentage> value - A <length> or <percentage> that specifies a translation along the X-axis. Equivalent to a translate() (2D translation) function with a single value specified.
  • Two <length-percentage> values - Two <length> or <percentage> that specify the X and Y axis translation values (respectively) of a 2D translation. Equivalent to a translate() (2D translation) function with two values specified.
  • Three values - Two <length-percentage> and single <length> values that specify the X, Y, and Z axis translation values (respectively) of a 3D translation. Equivalent to a translate3d() (3D translation) function.
  • none - Specifies that no translation should be applied.
18
Q

What does the rotate CSS property do?

A

The rotate CSS property allows you to specify rotation transforms individually and independently of the transform property.

This maps better to typical user interface usage, and saves having to remember the exact order of transform functions to specify in the transform property.

19
Q

What is the syntax of the rotate CSS property?

A

Syntax

/* Keyword values */
rotate: none;

/* Angle value */
rotate: 90deg;
rotate: 0.25turn;
rotate: 1.57rad;

/* x, y, or z axis name plus angle */
rotate: x 90deg;
rotate: y 0.25turn;
rotate: z 1.57rad;

/* Vector plus angle value */
rotate: 1 1 1 90deg;

Values

  • angle value - An <angle> specifying the angle to rotate the affected element through, around the Z axis. Equivalent to a rotate() (2D rotation) function.
  • x, y, or z axis name plus angle value - The name of the axis you want to rotate the affected element around (“x”, “y”, or “z”), plus an <angle> specifying the angle to rotate the element through. Equivalent to a rotateX()/rotateY()/rotateZ() (3D rotation) function.
  • vector plus angle value - Three <number>s representing an origin-centered vector that defines a line around which you want to rotate the element, plus an <angle> specifying the angle to rotate the element through. Equivalent to a rotate3d() (3D rotation) function.
  • none - Specifies that no rotation should be applied.
20
Q

What does the scale CSS property do?

A

The scale CSS property allows you to specify scale transforms individually and independently of the transform property.

This maps better to typical user interface usage, and saves having to remember the exact order of transform functions to specify in the transform value.

21
Q

What is the syntax of the scale CSS property?

A

Syntax

/* Keyword values */
scale: none;

/* Single values */
/* values of more than 1 or 100% make the element grow */
scale: 2;
/* values of less than 1 or 100% make the element shrink */
scale: 50%;

/* Two values */
scale: 2 0.5;

/* Three values */
scale: 200% 50% 200%;

Values

  • Single value - A <number> or <percentage> specifying a scale factor to make the affected element scale by the same factor along both the X and Y axes. Equivalent to a scale() (2D scaling) function with a single value specified.
  • Two values - Two <number> or <percentage> values that specify the X and Y axis scaling values (respectively) of a 2D scale. Equivalent to a scale() (2D scaling) function with two values specified.
  • Three values - Three <number> or <percentage> values that specify the X, Y, and Z axis scaling values (respectively) of a 3D scale. Equivalent to a scale3d() (3D scaling) function.
  • none - Specifies that no scaling should be applied.
22
Q

What does the transform-origin CSS property do?

A

The transform-origin CSS property sets the origin for an element’s transformations.

23
Q

What is the syntax of the transform-origin CSS property?

A

Syntax

/* One-value syntax */
transform-origin: 2px;
transform-origin: bottom;

/* x-offset | y-offset */
transform-origin: 3cm 2px;

/* x-offset-keyword | y-offset */
transform-origin: left 2px;

/* x-offset-keyword | y-offset-keyword */
transform-origin: right top;

/* y-offset-keyword | x-offset-keyword */
transform-origin: top right;

/* x-offset | y-offset | z-offset */
transform-origin: 2px 30% 10px;

/* x-offset-keyword | y-offset | z-offset */
transform-origin: left 5px -3px;

/* x-offset-keyword | y-offset-keyword | z-offset */
transform-origin: right bottom 2cm;

/* y-offset-keyword | x-offset-keyword | z-offset */
transform-origin: bottom right 2cm;

The transform-origin property may be specified using one, two, or three values, where each value represents an offset. Offsets that are not explicitly defined are reset to their corresponding initial values.

If a single <length> or <percentage> value is defined, it represents the horizontal offset.

If two or more values are defined and either no value is a keyword, or the only used keyword is center, then the first value represents the horizontal offset and the second represents the vertical offset.

Values

  • x-offset - Is a <length> or a <percentage> describing how far from the left edge of the box the origin of the transform is set.
  • offset-keyword - Is one of the left, right, top, bottom, or center keyword describing the corresponding offset.
  • y-offset - Is a <length> or a <percentage> describing how far from the top edge of the box the origin of the transform is set.
  • x-offset-keyword - Is one of the left, right, or center keyword describing how far from the left edge of the box the origin of the transform is set.
  • y-offset-keyword - Is one of the top, bottom, or center keyword describing how far from the top edge of the box the origin of the transform is set.
  • z-offset - Is a <length> (and never a <percentage> which would make the statement invalid) describing how far from the user eye the z=0 origin is set.
24
Q

What does the CSS transform: rotate(45deg); function do?

A

It rotates the element 45 degrees clockwise.

25
Q

Apply a CSS transform function that scales an element to twice its original size.

A
transform: scale(2);
26
Q

Which CSS transform function would you use to move an element 30 pixels to the right and 20 pixels down without disrupting the normal flow of the document?

A
transform: translate(30px, 20px);
27
Q

What does the CSS function transform: skewX(20deg); do to an element?

A

It skews the element 20 degrees along the X-axis.

28
Q

How would you combine multiple transform functions in a single declaration?

A

You can chain multiple functions together, like this: transform: rotate(45deg) scale(2);

29
Q

How to use CSS transform to rotate an element 45 degrees counter-clockwise?

A
transform: rotate(-45deg);
30
Q

Write a CSS rule that scales an element in the x-direction by 1.5 times and in the y-direction by 0.5 times.

A
transform: scaleX(1.5) scaleY(0.5);
31
Q

How to rotate an element around a fixed point (say 100px 100px)?

A

Set the transform-origin property to 100px 100px before applying the rotate function:

transform-origin: 100px 100px;
transform: rotate(45deg);