Pricing Blog

Why a div child forces the parent to grow and ignore flex 1?

  • uunicode-1408127513699553280

    unicodes

    3 months ago

    I have a parent div called main, which contains two children: c1 and c2.

    -c1 has a fixed width of 200px.
    -c2 is set to flex: 1 and also has width: 100%.

    Inside c2, there is another child element. When this child becomes visible, it forces c2 to grow, ignoring the flex: 1 behavior.

    If I add overflow: hidden to c2, everything works as expected. Without it, c2 doesn’t respect the flex: 1.

    Do you know why this happens?
  • lucasg-1408141047984296059

    Lucas G

    3 months ago

    flex 1 would mean it should grow
  • uunicode-1408154942283317288

    unicodes

    3 months ago

    changing flex-grow to 0 or 1 or flex-shrink, there is no difference. I can not understand why forces the parent to grow outside the flex rule. It grow's like flex was unset.
  • andreasmoller-1408707389376561253

    Andreas Møller

    3 months ago

    Unless you set a fixed width an element will grow to fit it’s content
  • uunicode-1408710963502252053

    unicodes

    3 months ago

    I believe the package horizontal scroll has something that does this. I do not have this error in other places.
  • andreasmoller-1408714028800413716

    Andreas Møller

    3 months ago

    That is possible