1

Why, when decreasing the height of the external container, does the height of the top-container and its elements (# first, # second,# third) not decrease?

Moreover, if you set the height directly for the top-container element, then the nested elements are still compressed ...

How to make a flex container with its descendants nested in another flex container shrink? :)

Height of items of .top-container must be 120px by default, but must shrink to 40px if it needed.

.outer-container {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  height: 450px;
}

.top-container {
  display: flex;
  flex-direction: column;
  
  background: rgba(200,0,0,.5);
}

.top-container div {
  border: 1px solid black;
  flex: 0 1 120px;
  min-height: 40px;
  display: flex;
  align-items: center;
}

.bottom-container {
  display: flex;
  flex-direction: column;
  flex: none;
  
  background: rgba(0,200,0,.5);
}

.bottom-container div {
  border: 1px solid black;
  display: flex;
  align-items: center;
}
<div class="outer-container">
   <div class="top-container">
    <div id="first">111</div>
    <div id="second">222</div>
    <div id="third">333</div>
  </div>
  <div class="bottom-container">
    <div id="four">4</div>
    <div id="five">5</div>
  </div>
</div>
NinoZombie
  • 11
  • 1
  • You've only set 3 dimensions in the "flex: 0 1 120px;" part and also is missing a unit on the 1, 0 can be used with no units but 1 must have a unit specified. I would suggest using css Calc combined with min-height, max height and units such as vh, vw, vmin and vmax as these are natively 'responsive'.. also why in the bottom container have you set display flex, but then stated flex none? – Ryan Stone Jan 15 '20 at 03:53
  • Thank you for the answer! `flex: 0 1 120px` is shorthand for `flex-grow: 0; flex-shrink: 1; flex-basis: 120px;` (see https://www.w3.org/TR/css-flexbox-1/#flex-property) Sure, i am will try `calc` and viewport properties, but i want to know where is problem in this flexbox approach :) – NinoZombie Jan 15 '20 at 04:21
  • Ok, got ya. You've set flex direction to be column, are you expecting the items dimensions to shrink as hardcoding them with pixel values will not work like this? – Ryan Stone Jan 15 '20 at 04:35
  • `min-height:0` to top and bottom container – Temani Afif Jan 15 '20 at 10:19

0 Answers0