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 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
215,940 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!