The CSS transform
property visually manipulates
element and transforms their appearance.
The transform
property applies
a 2D or 3D transformation to an element.
This property allows you to rotate, scale, move, skew, etc., elements.
The following code transform a div element.
div {
transform: transform-function || none; /* can list multiple, space-separated */
}
To get browser support with proper prefixes:
div { -webkit-transform: value; -moz-transform: value; -ms-transform: value; -o-transform: value; transform: value; }
transform: none|transform-functions|initial|inherit;
transform |
36.0 (4.0 -webkit-) | 10.0 (9.0 -ms-) | Yes | Yes | Yes |
<!DOCTYPE html>
<html>
<head>
<style>
div {<!--from w ww . j av a2 s . c o m-->
width: 100px;
height: 75px;
background-color: black;
border: 1px solid red;
}
div#div2 {
-webkit-transform: matrix(0.8,0.5,-0.5,0.6,0,0);;
-moz-transform: matrix(0.8,0.5,-0.5,0.6,0,0);;
-ms-transform: matrix(0.8,0.5,-0.5,0.6,0,0);;
-o-transform: matrix(0.8,0.5,-0.5,0.6,0,0);;
transform: matrix(0.8,0.5,-0.5,0.6,0,0);;
}
</style>
</head>
<body>
<div>Hello.</div>
<div id="div2">Hello. </div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
div {<!-- ww w . j a v a2s . c om-->
width: 100px;
height: 75px;
background-color: black;
border: 1px solid red;
}
div#div2 {
-webkit-transform: rotate(30deg);
-moz-transform: rotate(30deg);
-ms-transform: rotate(30deg);
-o-transform: rotate(30deg);
transform: rotate(30deg);
}
</style>
</head>
<body>
<div>Hello.</div>
<div id="div2">Hello. </div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
div {<!-- www . ja va 2 s. c o m-->
width: 100px;
height: 75px;
background-color: black;
border: 1px solid red;
}
div#div2 {
-webkit-transform: translate(10px);
-moz-transform: translate(10px);
-ms-transform: translate(10px);
-o-transform: translate(10px);
transform: translate(10px);
}
</style>
</head>
<body>
<div>Hello.</div>
<div id="div2">Hello. </div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
div {<!--from w w w.ja v a 2 s. c o m-->
width: 100px;
height: 75px;
background-color: black;
border: 1px solid red;
}
div#div2 {
-webkit-transform: translateX(10px);
-moz-transform: translateX(10px);
-ms-transform: translateX(10px);
-o-transform: translateX(10px);
transform: translateX(10px);
}
</style>
</head>
<body>
<div>Hello.</div>
<div id="div2">Hello. </div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
div {<!--from w ww . j a v a 2s . co m-->
width: 100px;
height: 75px;
background-color: black;
border: 1px solid red;
}
div#div2 {
-webkit-transform: translateY(10px);
-moz-transform: translateY(10px);
-ms-transform: translateY(10px);
-o-transform: translateY(10px);
transform: translateY(10px);
}
</style>
</head>
<body>
<div>Hello.</div>
<div id="div2">Hello. </div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
div {<!--from ww w .ja va2 s . co m-->
width: 100px;
height: 75px;
background-color: black;
border: 1px solid red;
}
div#div2 {
-webkit-transform: scale(1.1);
-moz-transform: scale(1.1);
-ms-transform: scale(1.1);
-o-transform: scale(1.1);
transform: scale(1.1);
}
</style>
</head>
<body>
<div>Hello.</div>
<div id="div2">Hello. </div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
div {<!-- w w w.j av a 2s .c o m-->
width: 100px;
height: 75px;
background-color: black;
border: 1px solid red;
}
div#div2 {
-webkit-transform: scaleX(1.1);
-moz-transform: scaleX(1.1);
-ms-transform: scaleX(1.1);
-o-transform: scaleX(1.1);
transform: scaleX(1.1);
}
</style>
</head>
<body>
<div>Hello.</div>
<div id="div2">Hello. </div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
div {<!--from w ww . j a va 2 s . c o m-->
width: 100px;
height: 75px;
background-color: black;
border: 1px solid red;
}
div#div2 {
-webkit-transform: scaleY(1.1);
-moz-transform: scaleY(1.1);
-ms-transform: scaleY(1.1);
-o-transform: scaleY(1.1);
transform: scaleY(1.1);
}
</style>
</head>
<body>
<div>Hello.</div>
<div id="div2">Hello. </div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
div {<!--from w w w . j ava2 s . c o m-->
width: 100px;
height: 75px;
background-color: black;
border: 1px solid red;
}
div#div2 {
-webkit-transform: skew(10deg,10deg));
-moz-transform: skew(10deg,10deg));
-ms-transform: skew(10deg,10deg));
-o-transform: skew(10deg,10deg));
transform: skew(10deg,10deg));
}
</style>
</head>
<body>
<div>Hello.</div>
<div id="div2">Hello. </div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
div {<!-- w w w . j av a2 s . co m-->
width: 100px;
height: 75px;
background-color: black;
border: 1px solid red;
}
div#div2 {
-webkit-transform: skewX(10deg));
-moz-transform: skewX(10deg));
-ms-transform: skewX(10deg));
-o-transform: skewX(10deg));
transform: skewX(10deg));
}
</style>
</head>
<body>
<div>Hello.</div>
<div id="div2">Hello. </div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
div {<!-- www . j a v a 2 s .com-->
width: 100px;
height: 75px;
background-color: black;
border: 1px solid red;
}
div#div2 {
-webkit-transform: skewY(10deg));
-moz-transform: skewY(10deg));
-ms-transform: skewY(10deg));
-o-transform: skewY(10deg));
transform: skewY(10deg));
}
</style>
</head>
<body>
<div>Hello.</div>
<div id="div2">Hello. </div>
</body>
</html>