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

Lili Köves
Lili Köves
3,471 Points

Flex container problem - hover effect increases letter-spacing, but that changes width of flex containers. Why?

I am practicing what I learnt about flexbox and transitions. So I have two flex items side by side (<div class="secondary promo"> and <div class="terciary promo"> ), have some text inside both. Applied a transition that on hovering increases the letterspacing of these texts. Weirdly that also increases the width of their parent containers and I can not find out why. What does cause this and how can I solve this so that the parent containers do not change?

Here is a snapshot of my workspace: https://w.trhou.se/brz3htdhlp

Thank you for any tips or comments!

2 Answers

Steven Parker
Steven Parker
220,415 Points

The default for flex-basis is "auto".

But if you change it to something else, the containers should not expand:

  .supporting > div {
    flex-basis: 0;
  }

You could also use the shorthand: "flex: 1;"

Lili Köves
Lili Köves
3,471 Points

It perfectly worked! Thank you! May I ask what the > means in .supporting > div ? I noticed if that is missing the containers still do expand.

Steven Parker
Steven Parker
220,415 Points

The ">" symbol is the child combinator. The entire selector targets "DIV elements that are direct children of the element with class supporting".