3️⃣

6.3 2D Transformations

CSS transforms allow you to move, rotate, scale, and skew elements.

CSS 2D Transforms Methods

With the CSS transform property you can use the following 2D transformation methods:

  • translate()
  • rotate()
  • scaleX()
  • scaleY()
  • scale()
  • skewX()
  • skewY()
  • skew()
  • matrix()

The translate() Method

The translate() method moves an element from its current position (according to the parameters given for the X-axis and the Y-axis).

image

The rotate() Method

The rotate() method rotates an element clockwise or counter-clockwise according to a given degree.

Using negative values will rotate the element counter-clockwise.

image

The scale() Method

The scale() method increases or decreases the size of an element (according to the parameters given for the width and height).

image

The scaleX() Method

The scaleX() method increases or decreases the width of an element.

image

The scaleY() Method

The scaleY() method increases or decreases the height of an element.

image

The skewX() Method

The skewX() method skews an element along the X-axis by the given angle.

image

The skewY() Method

The skewY() method skews an element along the Y-axis by the given angle(difficult to do with our triangle so just imagine it)

The skew() Method

The skew() method skews an element along the X and Y-axis by the given angles. If the second parameter is not specified, it has a zero value.

The matrix() Method

The matrix() method combines all the 2D transform methods into one.

The matrix() method take six parameters, containing mathematic functions, which allows you to rotate, scale, move (translate), and skew elements.

The parameters are as follow: matrix(scaleX(),skewY(),skewX(),scaleY(),translateX(),translateY())

image

Previous Section

Next Section

⚖️

Copyright © 2021 Code 4 Tomorrow. All rights reserved. The code in this course is licensed under the MIT License. If you would like to use content from any of our courses, you must obtain our explicit written permission and provide credit. Please contact classes@code4tomorrow.org for inquiries.