Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8040097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:47:02+00:00 2026-06-05T03:47:02+00:00

I realise that CSS transitions always apply to the class that’s been added, not

  • 0

I realise that CSS transitions always apply to the class that’s been added, not removed. But I’m wondering if there is an elegant solution to my problem. I have a set of boxes, when hovered, they transition into a circle. When a button is pressed, they grow/shrink.

I’d like them to grow and shrink slowly, but turn into a circle/square quickly.

At the moment, they grow and shrink slowly, turn into a circle quickly, but turn back to a square slowly again. This is of course because the CSS transition duration for the boxes is set to the slow speed, and so when the circle class is removed, they revert back to the original speed. I have come up with a working solution (not included here) that uses setTimeout to add a “quick speed” class for a moment and take it away. It does solve the issue but it feels very ugly to me.

Have you guys ever come across this issue and thought of a better way? Or is this just beyond the scope of CSS transitions?

CSS:

.box {
    background: red;
    width: 100px;
    height: 100px;
    margin: 10px;
    -webkit-transition: all 2s;
}

.big {
  width: 300px;    
}

.circle {
    background: blue;
    border-radius: 50px;
    -webkit-transition-duration: .5s;
}

jQuery:

$('.box').on('mouseenter', function() {
    $(this).addClass('circle');            
})

$('.box').on('mouseleave', function() {
    $(this).removeClass('circle');            
})    

$('.makeBig').on('click', function() {
    $('.box').toggleClass('big');            
})

HTML:

<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<button class="makeBig">Grow!</button>

jsFiddle:

http://jsfiddle.net/VDyPG/1/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T03:47:05+00:00Added an answer on June 5, 2026 at 3:47 am

    It can be done using CSS3 alone. All you need to do is move all transitions to the .box rule, like this:

    .box {
         background-color: red;
         width: 100px;
         height: 100px;
         margin: 10px;
         -webkit-transition: width 2s, border-radius .5s, background-color .5s;
    }
    
    .big {
       width: 300px;    
    }
    
    .circle {
        background-color: blue;
        border-radius: 50px;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I realise there might be similar questions but I couldn't find one that was
I realise that similar questions have been asked before however none of the solutions
I realize that this question has been asked 100times but none that I have
I've realised that I'm going to need to use a css class on all
I'm trying to apply a CSS mask to an element that also has child
I'm not a developer, but savvy enough to look at HTML, CSS and PHP
I realise that IE is a bit rubbish at most things but I was
I realize that the CSS parser that GWT uses will only handle CSS2, but
I've come realize that jquery dialogs won't apply any CSS styles defined by the
I realise that you can open the google maps app ready for directions by

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.