Performing multiple transitions using CSS3 (2024)

'; var adpushup = adpushup || {}; adpushup.que = adpushup.que || []; adpushup.que.push(function() { adpushup.triggerAd(ad_id); });

For multiple transitions, use the CSS3 transition property, which is a shorthand property. It sets the property, duration, timing, and delay of the transition in a single line. Let’s say we changed the width and border-radius for the transition.

transition: width 2s, border-radius 2s;

Set the container div

To begin with, set a parent div −

<div class="container"> <div></div></div>

Set the transition

The transition is set using the transition property for the width and border-radius properties. The duration set is 2 seconds −

.container div { width: 300px; height: 100px; border-radius: 1px; background: rgb(25, 0, 255); border: 2px solid red; transition: width 2s, border-radius 2s;}

On hover

On hovering the mouse cursor, since we have set two transitions above, the shape will change −

.container:hover div { width: 100px; border-radius: 50%;}

Set multiple transitions with width and border-radius

The following is the code for performing multiple transitions using CSS3 −

Example

Here is the example −

<!DOCTYPE html><html><head> <style> .container div { width: 300px; height: 100px; border-radius: 1px; background: rgb(25, 0, 255); border: 2px solid red; transition: width 2s, border-radius 2s; } .container:hover div { width: 100px; border-radius: 50%; } </style></head><body> <h1>Multiple transitions example</h1> <div class="container"> <div></div> </div> <h2> Hover over the above div to reduce its width and to change it into circle </h2></body></html>

Set multiple transitions with width and height

Let us see another example for multiple transitions. The transition is set using the transition property for the width, height and background-color properties. The duration set is 2 seconds −

transition: width 3s, height, 3s, background-color 3s;

Example

Here is the example −

<!DOCTYPE html><html><head> <style> .container div { width: 300px; height: 100px; border-radius: 1px; background: rgb(25, 0, 255); border: 2px solid red; transition: width 3s, height, 3s, background-color 3s; } .container:hover div { width: 150px; height: 150px; background-color: orange; } </style></head><body> <h1>Multiple transitions example</h1> <div class="container"> <div></div> </div> <h2> Hover over the above div to reduce its width, height and background color </h2></body></html>
Kickstart Your Career

Get certified by completing the course

Get Started

Performing multiple transitions using CSS3 (31)

Advertisem*nts

';adpushup.triggerAd(ad_id); });

Performing multiple transitions using CSS3 (2024)
Top Articles
Latest Posts
Article information

Author: Gregorio Kreiger

Last Updated:

Views: 6254

Rating: 4.7 / 5 (77 voted)

Reviews: 84% of readers found this page helpful

Author information

Name: Gregorio Kreiger

Birthday: 1994-12-18

Address: 89212 Tracey Ramp, Sunside, MT 08453-0951

Phone: +9014805370218

Job: Customer Designer

Hobby: Mountain biking, Orienteering, Hiking, Sewing, Backpacking, Mushroom hunting, Backpacking

Introduction: My name is Gregorio Kreiger, I am a tender, brainy, enthusiastic, combative, agreeable, gentle, gentle person who loves writing and wants to share my knowledge and understanding with you.