YogeshChauhan . com

transform-origin Property in CSS

in CSS on February 16, 2021

transform-origin property to me is like hanging the object on a point and then using that point as a center to move the object.

The transform-origin property let us change the position of elements with transform property set.

If we have elements with 2D transformations set then we can pin the transform-origin point to move those elements in x- and y-axis. We can also do that for z-axis if we have 3D transformations set for an element.

transform-origin property has a default values of 50% 50% 0

That value is always set unless we define something else to be set.

As we can see that by default it pins the elements in the center of the element so when we ONLY specify the transform property, it will adjust according to that default pin set.

And if we move that pin using transform-origin property then it will use that new pin point to adjust the elements on x or y or z axis depending on the transform-origin property value.

All major browsers support it so feel free to use it.

Syntax


transform-origin: x-axis y-axis z-axis|initial|inherit;

x-axis and y-axis possible values are left, center, right, length and % but for z-axis only one possible value is length.

Examples

transform-origin: center

transform-origin: top left

transform-origin: 25% 25%

transform-origin: top left, transform: skewX(50deg)

Source: w3.org

amazon

Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #3 How to add Read More Read Less Button using JavaScript? #4 How to uninstall Cocoapods from the Mac OS? #5 How to Use SQL MAX() Function with Dates? #6 PHP Login System using PDO Part 1: Create User Registration Page

Recently Posted

Jun 16 What are Stored Procedures for SQL Server? Jun 16 What are Class Constants in PHP? Jun 15 A short basic guide on states in React Jun 15 How to define constants in PHP? Jun 15 How to define visibility for a property in PHP? Jun 15 How to use @if and @else in SCSS?

You might also like these

What are Controlled Components in React?ReactFULL OUTER JOIN in PostgresPostgresCommon Table Expressions (CTE) in PostgreSQLPostgresJavaScript arrays: a separate data type or Objects?JavaScriptWhat is a Strict Requirement in PHP 7 Function Declarations?PHPHow to create a flip effect with CSS?CSS