Be the first user to complete this post
|
Add to List |
Understanding the CSS 3 transition property syntax
The simplest way to remember what you need to do for applying CSS transitions is by asking yourself four questions.
Once you have answered these questions, you can apply your transition effects to an element as such:
.myDiv {
width: 10px; /* Initial width */
transition-property: width;
transition-duration: 2s;
transition-timing-function: 1s;
transition-delay: 1s;
}
.myDiv:hover {
width: 40px;
}
By defining the transition effect on the element itself, the transition is bidirectional. i.e. in our example above, it will take place on both - when mouse hover takes place and mouse hover ends.
You can also specify multiple properties at the same time as shown below.
.myDiv {
width: 10px; /* Initial width */
height: 15px;
transition-property: width, height;
transition-duration: 2s, 3s;
transition-timing-function: ease-in, ease-in;
transition-delay: 1s, 1s;
}
.myDiv:hover {
width: 40px;
height: 60px;
}
As a final note, you can use the shorthand technique to apply all effects in a single line;
Applying the above syntax to our previous example:
transition: <property> <duration> <timing-function> <delay>;
.myDiv {
width: 10px; /* Initial width */
height: 15px;
transition: width 2s ease-in 1s, height 3s ease-out 1s;
}
.myDiv:hover {
width: 40px;
height: 60px;
}
Related resources
Also Read:
- css specificity interview question
- Configuring sass with your nodejs applications
- How to horizontally center a flexible width button using only css
- center using css
- css : center element vertically and horizontally