Transitions describe how to execute a CSS property animation from one state to another state over time.
In this demo you can choose the transition code from the selection list on the left, or you can write your own in the CSS Code window. The chosen transition is applied to the box in the middle of the display (on the right).
Hover the box and see the transition defined in the CSS code of the selection.
Play with background-color, radius, width, border, ... by changing the box properties in the CSS window. Then hover the box and see the effect of the transition you've defined.
Try transition on a single and multiple properties. Try all on transition property (or just don't put a property).
Play with duration and delay in transition. Duration and delay parameters may be in seconds (s), milliseconds (ms), ... and may be fractional (.2s).
Hover the middle area and follow after left/botton transition of the box. The transition is different on hover from the transition when mouse is removed.
Experiment the following:
To sum up, there are three basic ways that you can approach CSS transitions.
There are 4 boxes in this demo. Each one has 'box' class and ids box1 - box4. Each box has initial width of 90px (see the definition of the .box).
When we hover the demo area (#demo-block), the width of each box is changed to 100% of the demo area (see the definition of #container:hover .box).Thus, transition takes place.
See transition delays defined for each box and compare their behaviour.
Note: negative delay can be used.
Question: What happens if the transition property is visibility? display? opacity?
Answer: visibility and display are non-animatable properties. Thus, you can't make a transition on them. opacity is animatable. Check this in display/visibility selection.
Note that sometimes we want to make an element hidden (visibility: hidden), so it can't react on mouse activity for example. But we want a transition from visible state to hidden. In such cases in order to use transition, we will use both visibility and opacity. We will define transition on visibility from hidden to visible state with transition duration set to 0s and non-zero transition delay. Opacity will be set to the desired transition. In such a way transition on opacity to 0 will be seen.