The CSS transform property has many different outcomes: skew, rotate, scale, translate etc. Today we are going to focus on the rotate effect, showing how it is used and an example of its use.
We are going to rotate an image 360 degree on hover to demonstrate its effect. A basic page has been set up with the image in the centre:
To rotate the image on hover we will need to add this code to our IMG styling in our CSS. For convenience my styling is in the head but note styling should go in an external CSS file. Below is my styling for the image above.
margin: 100px auto 0;
Rotating the image is actually pretty simple and requires two extra pieces of CSS styling. The first is to add the :hover pseudo class to our img tag. Once we have this in place we can add the transform style. See below:
I have included all browser prefixes: Chrome, IE, Firefox, Opera, to ensure it functions on the up to date browsers. As you can see the transform property itself takes different styles and rotate is one of them. The rotate style uses degrees to move an element, 360deg as shown above rotates the element around once.
The final property that needs to be inserted is the transition property. This allows us to see the element rotate. Without it there would be no smooth transition from one state to the next. See below:
margin: 200px auto 0;
-ms-transition:all 500ms linear;
-webkit-transition:all 500ms linear;
-moz-transition:all 500ms linear;
-o-transition:all 500ms linear;
transition:all 500ms linear;
We have added to our previous code above and again included the vendor prefixes. Check it out in your browser and see how it works. Cool effects and styling can be accomplished with the transform property. No need to add hover effects and instead can have more than just vertical and horizontal lines on a page… Preview CSS Rotate