Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

WDS81 - CSS Transitions

In the last few articles, we were learning about transformations CSS which includes some 2D as well as 3D transformations. Although transformations are good for changing some properties of the element, in many cases we want the user to see some spectacular changes on the webpage. We can make it possible using Css Transitions. Let's see how...

CSS Transitions

CSS transitions allow us to change property values smoothly from one value to other with specified time interval by us. For example, you can change the Width of div from 10px to 20px in the time of 3 seconds when the user hovers over it which will give visual effects to it.

How to implement the CSS Transitions?

To create a transition effect, we have to specify two things:
  • The CSS property we want to add effect to
  • The duration of effect
It is important to mention the duration, else there will have no effect as default duration is 0 seconds. Let's have a simple example:
In the above example, the initial width of div is 120px and it changes to 200px when hovered. If we do not mention line containing transition it will still change it's width when hovered but we will not see it' transition as the event will be completed in 0s. For Safari add the following line:
-webkit-transition: width 2s;

Change Several properties at Same Time

The following code will add a transition effect for both width and height properties of div with respective time duration of 3 and 6 seconds.
div {
-webkit-transition: width 3s, height 6s; /* Safari */
transition: width 3s, height 6s;
}
That's all for today. In the next article, we will see other important concepts about using CSS transitions in our code. Till the #keepCoding.


This post first appeared on The Coding Express, please read the originial post: here

Share the post

WDS81 - CSS Transitions

×

Subscribe to The Coding Express

Get updates delivered right to your inbox!

Thank you for your subscription

×