CSS3 2D Transform


Transform (w3.org ) is a CSS3 property that allows you to transform an element in a number of ways that include the Rotate, Skew, Scale and Translate. Another property Origin can be used to establish the starting point of the functions. These effects will work in all the lastest browsers except IE.

Problems


There are problems with Transform in some browsers at the moment
(January, 2011) the element edges look very ragged in Chrome and rotated text in Firefox is difficult to read.  You might want to test this page in all browsers before you go ahead.

Will It Enhance the Design


Before we start I just want to stress that although using transform can be fun, and its very easy to implement, you need to ask yourself do I really need it? Will it enhance the design of the page or just be a distraction.

Rollovers


Roll-over the images below to see the effect.They are in this order: skew, scale, rotate, translate. A transition has been added to ease the animation between one stage and another. The transition only works in Webkit browsers. I will address transitions in a later article.


CSS3 for different browsers


You will need to include different lines of code for the various browsers. Older versions of all browsers will not support CSS3; below is the code for a particular browser along with the version that first started to read this particular css:

-moz- Firefox 3.5 and up
-webkit- Chrome and Safari 3.1 and up
-o- Opera 10.5 and up
-ms- Internet Explorer 9 and up
Over time the different pre-fixes will not longer be required and you will only need: transform.

 

Rollover the small images below to get a better idea of the changes that occure when an element is given a particular function.

Transform - Rotate


The number for your rotation can either be stated in positive or negative degrees:

Images One


.rotateOne{
transform: rotate(-5deg);
-moz-transform:rotate(-5deg);
-webkit-transform: rotate(-5deg);
-ms-transform: rotate(-5deg);
-o-transform: rotate(-5deg);
}

Transition - Timing Function


ease:

start slow, then gets fast, ends slow

ease-in:

slow start

ease-out:

slow end

ease-in-out:

slow start, slow end

cubic-bezier:

four points of the curve are specified (x1, y1, x2, y2). Values 0-1

Transition - Duration


The length of time the of the transition
ms - milliseconds
s- seconds


 

All of the following examples will only state transform but you will need to include all of the vendor code for the various browsers.

Transform - Rotate Origin

The default origin of the transform is the center of the element. If you want to change this you need to add an origin position which could be any of the following:
top left
top right
bottom left
bottom right

Images Two


.rotateTwo{
transform:rotate(5deg);
transform-origin: top right;
}
This does not appear to make much of a difference but it does move it to the right a bit and the angle is slightly different.




Transform - Rotate Translate


With Translate you can move the element from its original position, using the x and y coordinates. The code is:

Image Three


.rotateThree{
transform:rotate(5deg)translate(25px, 25px);
}

Translation will work with any of the other functions. You are going to find that you will probably want to move a rotated or skewed element from its original position because once either of these functions have been applied to an object it will take up a different position on the page which may not work well. Also if you use Translation to reposition an element (instead of margins or position) it will not effect the element in older browsers that do not read Transform.







Transform - Rotate Text



Text One


.rotateText{
transform:(-5deg);
}
Rotated text does not display well in Firefox. At the moment I am viewing in Firefox version 3.6.13, hopefully this will improve in later versions.







Transform - Skew


The element is skewed from its x and y coordinates

Images Four


.skewFour{
transform: skew(2deg, 20deg);
}













Transform - Scale



Images Five


The larger image does not have is not associated with any css
The following code is on hover of the smaller image

.scale{
transform: scale(2.0);
}

#name:hover{

transform:scale(2);
transition-timing-function: ease-out;
transition-duration: 500ms;
}



Transform - Matrix


Matrix brings all the numbers together. This is a lot more complicated than it sounds, so I am not going to get into it at the moment. Here is the link to Matrix on W3C if you want to experiment.

used for spacing

ONE

santa fee - rotation example







The hover on the smaller image has (-25deg)
#name:hover{
transform:rotate(-25deg);
transition-timing-function: ease-out;
transition-duration: 500ms;
}
You also need to include all of the vendor code








TWO

santa fee - rotation example





#name:hover{
transform:rotate(5deg);
transform-origin: top right;
}


santa fee - rotation example

THREE


santa fee - rollover example





#name:hover{
transform: translate(100px);
transition-timing-function: ease-out;
transition-duration: 500ms;

}

I am just have the image above move from

left to right with x cordinate on the rollover.

If I add the x and y it does not work correctly
in Firefox but works fine in the Webkit browsers.


ONE TEXT


Text does not display well in Firefox
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas in leo eget elit ultrices ullamcorper quis nec orci. Sed eget dolor sed turpis vulputate porta eu sit amet enim. Ut arcu libero, iaculis et laoreet et, porttitor sit amet lectus.






FOUR

santa fee - skew example
santa fee - rollover example





#name:hover{
transform:skew(15deg, 15deg);
}




spacer only santa fee - rotation example

FIVE

santa fee - rollover example

 

 

 

 

 

 



code

color

CSS

design

type

writing

info arch

the net

php

seo

user

usabilty


be inspired


my notes