Monday 26 December 2011

css3 Transforms - The translate() Method

The translate() Method:

 With the translate() method, the element moves from its current position, depending on the parameters given for the left (X-axis) and the top (Y-axis) position:

Syntax:

 div{
 transform: translate(50px,100px);
 -ms-transform: translate(50px,100px); /* IE 9 */
 -webkit-transform: translate(50px,100px); /* Safari and Chrome */
 -o-transform: translate(50px,100px); /* Opera */
 -moz-transform: translate(50px,100px); /* Firefox */
 }

Example:

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml">
 <head>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 <title> translate Method </title>
 <style type="text/css">
 body{margin:0;padding:50px; }
 div
 {
 width:200px;
 height:75px;
 background-color: #CC9900;
 border:1px solid black;
 }
 div#div2
 {
 transform:translate(50px,100px);
 -ms-transform:translate(50px,100px); /* IE 9 */
 -moz-transform:translate(50px,100px); /* Firefox */
 -webkit-transform:translate(50px,100px); /* Safari and Chrome */
 -o-transform:translate(50px,100px); /* Opera */
 }
 </style>
 </head>
 <body>
 <div>Hello. This is a DIV element.</div>
 <div id="div2">World. This is a DIV element.</div>
 </body>
 </html>

Result:

No comments:

Post a Comment