0

I have the following layout, and want to update the content (innerHTML) of element "three". However, when I do so, it unwantedly resizes the element, changing the width of all my columns. How do I prevent this happen? I do not! want any changes to any div's width, when pushing the "update" button.

The only way I got it to work is replace flex-grow with flex:1 0 1%; on element "three". But that 1% (or any % really except 100) make no sense to me. Why would that flex-basis make it ok? it feels like a hack, and not the actual correct way of doing it.

function update() {
  var text = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s.";
  document.querySelector(".three").innerHTML = text;
}
html,
body {
  margin: 0;
  padding: 0;
}

.container {
  background-color: tomato;
  display: flex;
  height: 100%;
  min-height: 100vh;
  color: #ffffff;
}

.one {
  width: 10%;
  background-color: grey;
  height: auto;
}

.two {
  width: 200px;
  height: 100vh;
  background-color: green;
  display: inline-block;
  position: sticky;
  top: 0;
}

.three {
  background-color: orange;
  flex-grow: 1;
  height: 100vh;
  min-height: 3000px;
}

.four {
  width: 200px;
  overflow-y: hidden;
}

.five {
  width: 10%;
  background-color: dodgerblue;
  height: auto;
}
<div class="container">

  <div class="one">
    one
  </div>

  <div class="two">
    two
    <br/>
    <button id="update" onclick="update()">update</button>
  </div>

  <div class="three">
    three
  </div>

  <div class="four">
    four
  </div>

  <div class="five">
    five
  </div>

</div>
Jason
  • 387
  • 3
  • 13
  • 1
    and what width should have "three" – serge Oct 25 '22 at 12:13
  • the remaining width available after ONE, TWO, FOUR, FIVE as their widths are specified in px and percent. Just like it is before you press the "update" button. I dont want the layout shift when its pressed. – Jason Oct 25 '22 at 12:31
  • 1
    please see this one https://stackoverflow.com/a/74194171/961631 – serge Oct 25 '22 at 12:38
  • 1
    @serge sorry for delay, i just tried it and its exactly! what i needed and not the hacky way I did with flex:1 0 1%; - thank you!!!!! – Jason Oct 25 '22 at 14:01
  • I simplified a little the css (update) – serge Oct 25 '22 at 14:21
  • 1
    div:not(.three) , clever. i did not know about that. – Jason Oct 25 '22 at 15:00

0 Answers0