Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS CSS Transitions and Transforms Getting Started with CSS Transitions Transitioning Multiple Properties

Tatiana Perry
Tatiana Perry
17,156 Points

Is there a reason why the transition properties are going in the .button class and not the .button:hover?

This is the css for this lesson, which changes the button color background on hover.

.button {
  color: #4a89ca;
  border: 2px solid;
  transition-duration: 0.4s;
  transition-property: background, border-radius, color;
}

.button:hover{
 color: #fff;
 background-color:#4a89ca;
 border-radius: 1em;
}

.button:active{
  background: #a33830;
}

When I move the transition properties down to .button:hover it does the same thing. Why are they in the .button property? My first thought would be to add all the transitions under hover since that is the state I am targeting. Why does it work under the class .button and is there a reason why its not being done under button:hover?

.button {
    color: #4a89ca;
  border: 2px solid;
/*
  transition-duration: 0.4s;
  transition-property: background, border-radius, color;
*/
}

.button:hover{
 color: #fff;
 background-color:#4a89ca;
 border-radius: 1em;
 transition-duration: 0.4s;
 transition-property: background, border-radius, color;
}

.button:active{
  background: #a33830;
}

1 Answer

Steven Parker
Steven Parker
229,732 Points

Take a closer look. When you move your properties to the :hover rule, it might do the same thing when the mouse goes over, but when the mouse goes out, the states will snap back with no transition.

Try making the duration a bit longer if the difference is not obvious.

There are times when you might want a transition to only occur one-way, but if you want the effect to work both ways, you have to put the properties (at least the duration) in the base rule.

Tatiana Perry
Tatiana Perry
17,156 Points

I see what you mean. I had to change the duration as you suggested. Thanks!