Working with CSS3 2D Transform Functions

CSSWeb DevelopmentFront End Technology

2D transforms are used to re-change the element structure as translate, rotate, scale, and skew.

Following are some of the 2D transform functions −

Sr.No.Value & Description
1matrix(n,n,n,n,n,n)
Used to defines matrix transforms with six values
2translate(x,y)
Used to transforms the element along with x-axis and y-axis
3translateX(n)
Used to transforms the element along with x-axis
4translateY(n)
Used to transforms the element along with y-axis
5scale(x,y)
Used to change the width and height of element
6scaleX(n)
Used to change the width of element

Following is the code showing 2D transform functions in CSS3 −

Example

 Live Demo

<!DOCTYPE html>
<html>
<head>
<style>
body {
   font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}
div {
   width: 100px;
   height: 100px;
   background-color: rgb(98, 0, 255);
   margin: 20px;
   display: inline-block;
   color: white;
}
.rotate {
   transform: rotate(20deg);
}
.translate {
   transform: translate(30px, 20px);
}
.scale {
   transform: scale(2, 1);
   margin-left:70px;
}
.skew {
   transform: skew(20deg);
}
</style>
</head>
<body>
<h1>2D transform functions</h1>
<div class="rotate">ROTATE</div>
<div class="skew">
SKEW
</div>
<div class="scale">SCALE</div>
<div class="translate">TRANSLATE</div>
</body>
</html>

Output

The above code will produce the following output −

raja
Published on 11-May-2020 13:16:20
Advertisements