0

How can we make the flex items' height grow only when the text in the second flex item is full of the text?

Someone pointed me to this link, but it's not working for me.

function addDummyText() {
  const span = document.getElementById("second-row-span");

  span.textContent = span.textContent + " Lorem ipsum dolor sit amet ";
}
html,
body {
    height: 100%;
}

.flex-container {
    display: flex;
    flex-direction: column;
    flex-wrap: nowrap;
    justify-content: flex-start;
    align-content: stretch;
    align-items: stretch;
    height: 100%;
    }

.flex-item:nth-child(1) {
    order: 0;
    flex: 1 1 auto;
    align-self: auto;
    background-color: red;
    }

.flex-item:nth-child(2) {
    order: 0;
    flex: 2 1 auto;
    align-self: auto;
  background-color: blue;
    }

.flex-item:nth-child(3) {
    order: 0;
    flex: 0 1 auto;
    align-self: auto;
  background-color: grey;
    }
<div class="flex-container flex-container-style fixed-height">
  <div class="flex-item"><span contenteditable=""></span><span class="counter">1 <input type="button" onclick="addDummyText()" value="add text" /> </span></div>
  <div class="flex-item"><span contenteditable=""></span><span id="second-row-span" class="counter">2</span></div>
  <div class="flex-item"><span contenteditable=""></span><span class="counter">3</span></div>
</div>

enter image description here

Wildan Muhlis
  • 1,553
  • 2
  • 22
  • 43

0 Answers0