Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Stretching Issue with children Overflow

I’ve set up a container div with an overflow set to auto. When a child element contains long text, it naturally overflows the container, triggering a horizontal scroll (x-scroll). While this is expected, the challenge arises when the child element fails to stretch to the full width of the container, leaving it looking truncated as the container is scrolled.

<div class="flex flex-col h-full">
  <div class="h-full container">
    <div class="flex p-2 items-center item selected">
      <div class="flex items-center">-</div>
      <div class="whitespace-nowrap">text1</div>
    </div>
    <div class="flex p-2 items-center item">
      <div class="flex items-center">-</div>
      <div class="whitespace-nowrap">text2</div>
    </div>
  </div>
</div>
.container {
  overflow: auto;
  resize: horizontal;
  min-width: 10rem;
  max-width: 25rem;
}

.item {
  white-space: nowrap;
}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You should fix the .flex class. Please change display:flex to display:inline-flex.

This happens as the inherent nature of block elements, which always take 100% width, irrespective of text wrapping.

In contrast, inline elements dynamically adjust their width based on the content, and this characteristic is precisely what we are capitalizing on in this context.

.item {
  white-space: nowrap;
}

.flex-col {
  flex-direction: column;
}

.flex {
  display: inline-flex;
}

.container {
  overflow: auto;
  resize: horizontal;
  min-width: 10rem;
  max-width: 25rem;
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading