Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

CSS CSS Transitions and Transforms Getting Started with CSS Transitions Creating Your First Transition with transition-duration

Elias Paiva
Elias Paiva
7,348 Points

Why was the declaration "transition-duration: 1s;" added to ".button" and not ".button:hover"?

I thought that it was going to be added to the hover declariton, but I tested it and it works both ways. So why one over the other)

1 Answer

Hi Eias!

I think that's just the customary way to approach it.

Think of button as the starting point and button: hover as the endpoint

My way of looking at it is you include the transition/duration on the starting point.

Does that make sense?

BTW, I tested it too, and it does SEEM to work either way.

NOTE: But there is a subtle difference (which I didn't notice either at first):

When transition-duration is assigned to button, the duration works BOTH when you hover on and hover off.

When it is assigned to button:hover, however you get a smooth, slow transition when you hover on only.

When you hover off, it abruptly reverts back (without the smooth, slow transition).

(Test it again and you'll see it.)

So, I learned something new, too!?! LOL (Thank you for that!)

More info:



I hope that helps.

Stay safe and happy coding!