0

flex 1 wont fill available space and I don't know why?

.container {
      display: flex;
    align-items: flex-start;
    justify-content: space-between;
    background: #FFFFFF;
    box-shadow: 0px 8px 20px rgb(0 0 0 / 8%);
    border-radius: 45px;
    padding: 30px;
    margin-bottom: 40px;
}

.sub-container-one {
  font-size: 100px;
}

.sub-sub-container-two {
    display: flex;
    align-items: center;
    /* this apparently should work but it doesn't */
      flex: 1;
}
<div class="container">
  <div class="sub-container-one">
    ftftftftftftf
  </div>
  <div class="sub-container-two">
    <div class="sub-sub-container-two">
      ghghghghghghghghghghghg
    </div>
  </div>
</div>

Fill remaining vertical space with CSS using display:flex

flex: 1; /* 1 and it will fill whole space left if no flex value are set to other children*/

There are no other children in the div

Howcome I can't center sub-sub-container-two ?

Flexbox: center horizontally and vertically

I found this question

It suggests to use a fix height but I can't do this because it needs to support multiple entries.

how do you make flex 1 fill available space?

kawnah
  • 2,805
  • 6
  • 43
  • 84
  • 1
    What to do mean by "fill available space"? Which space you want to fill with which container? – Verity Dec 07 '21 at 21:46

1 Answers1

0

Your flex children are .sub-container-one and .sub-container-two, not .sub-sub-container-two, so all your settings for .sub-sub-container-two should be applied to .sub-container-two. And horizontal centering is done with justify-content, BTW (not with align-items)

.container {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    background: #FFFFFF;
    box-shadow: 0px 8px 20px rgb(0 0 0 / 8%);
    border-radius: 45px;
    padding: 30px;
    margin-bottom: 40px;
}

.sub-container-one {
  font-size: 100px;
}

.sub-container-two {
    display: flex;
    justify-content: center;
    flex: 1;
}
<div class="container">
  <div class="sub-container-one">
    ftftftftftftf
  </div>
  <div class="sub-container-two">
    <div class="sub-sub-container-two">
      ghghghghghghghghghghghg
    </div>
  </div>
</div>

Also note that your container settings align-items: flex-start; and justify-content: space-between; have no effect if you allow the items to grow and fill the available width.

Johannes
  • 59,058
  • 16
  • 59
  • 114