3D Transforms

CSS3 allows you to format your elements using 3D transforms.
In this chapter you will learn about some of the 3D transform methods:
  • rotateX()
  • rotateY()
Click on the elements below, to see the difference between a 2D transform and a 3D transform:
2D rotate
3D rotate


Browser Support

PropertyBrowser Support
transform
Internet Explorer and Opera does not yet support 3D transforms (They support only 2D transforms).
Firefox requires the prefix -moz-.
Chrome and Safari requires the prefix -webkit-.

The rotateX() Method

Rotate X
With the rotateX() method, the element rotates around its X-axis at a given degree.
OperaSafariChromeFirefoxInternet Explorer

Example

<!DOCTYPE html>
<html>
<head>
<style type="text/css"> 
div
{
width:100px;
height:75px;
background-color:red;
border:1px solid black;
}
div#div2
{
transform:rotateX(120deg);
-webkit-transform:rotateX(120deg); /* Safari and Chrome */
-moz-transform:rotateX(120deg); /* Firefox */
}
</style>
</head>
<body>

<p><b>Note:</b> Internet Explorer and Opera does not support the rotateX method.</p>

<div>Hello. This is a DIV element.</div>

<div id="div2">Hello. This is a DIV element.</div>

</body>
</html>

Try it yourself in Notepad or Dreamweaver by coping and pasting the code above.


The rotateY() Method

Rotate Y
With the rotateY() method, the element rotates around its Y-axis at a given degree.
OperaSafariChromeFirefoxInternet Explorer

Example


<!DOCTYPE html>
<html>
<head>
<style type="text/css"> 
div
{
width:100px;
height:75px;
background-color:red;
border:1px solid black;
}
div#div2
{
transform:rotateY(130deg);
-webkit-transform:rotateY(130deg); /* Safari and Chrome */
-moz-transform:rotateY(130deg); /* Firefox */
}
</style>
</head>
<body>

<p><b>Note:</b> Internet Explorer and Opera does not support the rotateY method.</p>

<div>Hello. This is a DIV element.</div>

<div id="div2">Hello. This is a DIV element.</div>

</body>
</html>

Try it yourself in Notepad or Dreamweaver by coping and pasting the code above.


Transform Properties

The following table lists all the transform properties:
PropertyDescriptionCSS
transformApplies a 2D or 3D transformation to an element3
transform-originAllows you to change the position on transformed elements3
transform-styleSpecifies how nested elements are rendered in 3D space3
perspectiveSpecifies the perspective on how 3D elements are viewed3
perspective-originSpecifies the bottom position of 3D elements3
backface-visibilityDefines whether or not an element should be visible when not facing the screen3

3D Transform Methods

FunctionDescription
matrix3d
(n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n)
Defines a 3D transformation, using a 4x4 matrix of 16 values
translate3d(x,y,z)Defines a 3D translation
translateX(x)Defines a 3D translation, using only the value for the X-axis
translateY(y)Defines a 3D translation, using only the value for the Y-axis
translateZ(z)Defines a 3D translation, using only the value for the Z-axis
scale3d(x,y,z)Defines a 3D scale transformation
scaleX(x)Defines a 3D scale transformation by giving a value for the X-axis
scaleY(y)Defines a 3D scale transformation by giving a value for the Y-axis
scaleZ(z)Defines a 3D scale transformation by giving a value for the Z-axis
rotate3d(x,y,z,angle)Defines a 3D rotation
rotateX(angle)Defines a 3D rotation along the X-axis
rotateY(angle)Defines a 3D rotation along the Y-axis
rotateZ(angle)Defines a 3D rotation along the Z-axis
perspective(n)Defines a perspective view for a 3D transformed element

Leave a Reply