With CSS3, we can add an effect when changing from one style to another, without using Flash or JavaScript.
Mouse over the element below:
The numbers in the table specify the first browser version that fully supports the property.
Numbers followed by -webkit-, -moz-, or -o- specify the first version that worked with a prefix.
Property | |||||
---|---|---|---|---|---|
transition | 10.0 | 26.0 4.0 -webkit- |
16.0 4.0 -moz- |
6.1 3.1 -webkit- |
12.1 10.5 -o- |
transition-delay | 10.0 | 26.0 4.0 -webkit- |
16.0 4.0 -moz- |
6.1 3.1 -webkit- |
12.1 10.5 -o- |
transition-duration | 10.0 | 26.0 4.0 -webkit- |
16.0 4.0 -moz- |
6.1 3.1 -webkit- |
12.1 10.5 -o- |
transition-property | 10.0 | 26.0 4.0 -webkit- |
16.0 4.0 -moz- |
6.1 3.1 -webkit- |
12.1 10.5 -o- |
transition-timing-function | 10.0 | 26.0 4.0 -webkit- |
16.0 4.0 -moz- |
6.1 3.1 -webkit- |
12.1 10.5 -o- |
CSS3 transitions are effects that let an element gradually change from one style to another.
To do this, you must specify two things:
Add a transition effect on the width property, with a duration of 2 seconds:
Note: If the duration part is not specified, the transition will have no effect, because the default value is 0.
The transition effect will start when the specified CSS property changes value. A typical CSS property change would be when a user mouse-over an element:
Note: When the cursor mouse out of the element, it gradually changes back to its original style.
To add transition effects for more than one CSS property, separate the properties with a comma:
Add transition effects on width, height, and transformation:
The example below uses all the four transition properties:
The same transition effects as the example above. However, here we are using the shorthand transition property:
The following table lists all the transition properties:
Property | Description | CSS |
---|---|---|
transition | A shorthand property for setting the four transition properties into a single property | 3 |
transition-delay | Specifies when the transition effect will start | 3 |
transition-duration | Specifies how many seconds or milliseconds a transition effect takes to complete | 3 |
transition-property | Specifies the name of the CSS property the transition effect is for | 3 |
transition-timing-function | Specifies the speed curve of the transition effect | 3 |