Having trouble with a deeply nested flex container not scrolling properly despite setting a minimum height?

I'm struggling with achieving overflow in div.stretchy within my flex layout. I want div.stretchy to expand to the edge of the page and then overflow its content. Despite experimenting with various combinations of min-height: 0 and overflow: hidden, I can't get div.stretchy to shrink as desired. Following guidance from a relevant StackOverflow post, I've attempted different approaches without success.

body {
  margin: 0;
}

.page-wrapper {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

.sidebar {
  background: blue;
  flex: 0 0 40px;
}

.main {
  background: green;
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}

.topbar {
  display: flex;
  flex: 0 0 40px;
  background-color: red;
}

.content {
  display: flex;
  overflow: auto;
}

.row {
  display: flex;
}

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

.grow {
  flex-grow: 1;
}

.card {
  height: 300px;
  border: solid 1px;
  min-width: 600px;
}

.card .row {
  justify-content: space-between;
}

.wrapper {
  padding: 16px;
  height: fit-content;
}

.stats {
  padding: 8px;
  background-color: pink;
}

.overflow-hidden {
  overflow: hidden;
}

.body .column {
  background-color: indigo;
}

.wide-content {
  background-color: yellow;
  height: 50px;
  width: 800px;
}

.block {
  flex: none;
  width: 300px;
  height: 200px;
  &:nth-of-type(odd) {
    background: darken(green, 10%);
  }
}
<div class="page-wrapper">
  <div class="sidebar">sidebar</div>
  <div class="main">
    <div class="topbar">topbar</div>
    <div class="content">
      <div class="wrapper">
        <div class="card column grow">
          <div class="stats row">
            <span>12345</span>
            <span>12345</span>
            <span>12345</span>
          </div>
          <div class="body row grow">
            <div class="column">
              <span>Dynamic Width Content</span>
            </div>
            <div class="stretchy column grow overflow-hidden">
              <div class="wide-content grow"></div>
            </div>
            <div class="column">
              <span>Dynamic Width Content</span>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>

Answer №1

This battle is going to be a challenging one. The enemy we are facing is sly, deceptive, and ruthless. I strongly believe that our best approach would be to initiate a massive carpet bombing campaign, saturating the entire area with min size overrides. This tactic should eliminate 80% of the problem. We can then follow up by sending in ground troops to complete the mission :-)

* {
  min-width: 0 !important;
  min-height: 0 !important;
}

.page-wrapper {
  display: flex;
  height: 100vh;
  /* width: 100vw; */
  /* overflow: hidden; */
}

.sidebar {
  background: cornflowerblue;
  /* flex: 0 0 40px; */
  flex: 0 0 100px; /* changed for demo purposes */
}

.main {
  background: lightgreen;
  display: flex;
  flex-direction: column;
  flex: 1;
}

.topbar {
  display: flex;
  flex: 0 0 40px;
  background-color: orangered;
}

.content {
  display: flex;
  /* overflow: auto; */ 
  flex: 1; /* added */
}

.row {
  display: flex;
}

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

.grow {
  flex-grow: 1;
}

.card {
  /* height: 300px; */
  border: solid 1px;
  min-width: 600px;
}

.stretchy {
  overflow: auto;
}

.card .row {
  justify-content: space-between;
}

.wrapper {
  padding: 16px;
  /* height: fit-content; */
  display: flex; /* added */
}

.stats {
  padding: 8px;
  background-color: pink;
}

.overflow-hidden {
  /* overflow: hidden; */
}

.body .column {
  background-color: violet;
}

.wide-content {
  background-color: yellow;
  height: 50px;
  width: 800px;
}

body {
  margin: 0;
}


/* 
.block {
  flex: none;
  width: 300px;
  height: 200px;
  &:nth-of-type(odd) {
    background: darken(green, 10%);
  }
}
*/
<div class="page-wrapper">
  <div class="sidebar">sidebar</div>
  <div class="main">
    <div class="topbar">topbar</div>
    <div class="content">
      <div class="wrapper">
        <div class="card column grow">
          <div class="stats row">
            <span>12345</span>
            <span>12345</span>
            <span>12345</span>
          </div>
          <div class="body row grow">
            <div class="column">
              <span>Dynamic Width Content</span>
            </div>
            <div class="stretchy column grow overflow-hidden">
              <div class="wide-content grow">test<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br></div>
            </div>
            <div class="column">
              <span>Dynamic Width Content</span>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>

Check out the jsFiddle demo here

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

In JavaScript, a dropdown menu becomes active when clicked on and becomes inactive when clicking outside of it

My script is not functioning properly when I click outside of the drop-down menu of the "Sign in" button. View jsfiddle Demo $(document).ready(function() { $(".openmenu").click(function() { var X = $(this).attr('id'); if (X == 1) { ...

Whenever I attempt to execute my .html and .js files, I encounter the error message: "Uncaught SyntaxError: Unexpected token <"

Just starting out in react.js, I decided to include CDN links to compile some basic react.js code into my html. Unfortunately, I encountered this error: "Uncaught SyntaxError: Unexpected token <" I did some research and found a suggestion to add: t ...

Using JavaScript, what is the method for inputting values into a window.prompt()?

I've been working on a project that involves scraping basic HTML pages from an internal server at my workplace. When I visit these pages, a popup window similar to a windows.prompt() appears, asking for a username and password with the message "Enter ...

Develop a design utilizing a foundational database entity

I'm new to AngularJS and I am seeking guidance on how to properly separate the model from the controller. In my previous experience, I have always integrated models within the controllers. For example: angular.module("app").controller("customerContr ...

Positioning <tr> elements with absolute precision within a intricate layout

I am faced with the challenge of developing a complex UI control. The structure consists of a left-side TreeTable component, implemented using a <table> element, and a right-side SVG component that displays data corresponding to each row of the left ...

The act of sorting an item in jQuery triggers a reordering of items

I am working with a collection of items that represent different layers within div elements. One of my goals is to ensure that when I rearrange these items, their corresponding div layers are also sorted accordingly. Here is the list of sortable items: & ...

Including a logo and navigation bar in the header while collaborating with different subregions

I'm having trouble getting a picture to display in the header alongside a horizontal menu. I've divided the header into two sections: img and navbar (html). The navbar is showing up correctly, but the image isn't appearing. Any suggestions o ...

Javascript Form Verification (beginner coder)

I am having issues with my HTML form validation using JavaScript. Everything was working fine until I added the regular expression match part. Now, whenever the submit button is clicked, the page refreshes without performing any of the form validation belo ...

Utilizing JQuery for Redirection

I need help with a specific issue on my website. Visit this link On the webpage, there is a button labeled "get a quote". When users click on this button, I want them to be redirected to google.com. I attempted to achieve this using the following JavaSc ...

Can the individual headers of an ag-grid column be accessed in order to apply an on-mouseover event with a specific method?

In my current project, I am utilizing ag-grid to create a dynamic web-application that combines tools from various Excel files into one cohesive platform. One of the Excel features I am currently working on involves displaying a description when hovering ...

Eliminating the gap between three HTML columns

I am facing an issue with reducing the space between 3 col-md-4 elements in my code. I attempted to decrease the margin between them while adjusting the padding on the first and last columns. However, this solution resulted in the image columns becoming mi ...

Verify if any choices are available before displaying the div block

I need to determine if there is a specific option selected in a dropdown menu, and then display a div if the option exists, otherwise hide it. I'm not just checking the currently selected option, but all available options. if (jQuery(".sd select opti ...

Trouble uploading document into mysql database

Creating a form in HTML using Bootstrap involves including specific elements for file uploads like this: <div class="form-group"> <label for="inputPic">Item Image</label> <input type="file" name="inputPic"> <p class= ...

Several validation checks - logic malfunction

I have implemented a validation feature for passwords on a form, but I suspect there may be a logic error in my code that I haven't caught yet (blame it on the coffee machine!). Take a look at the JavaScript below: <script type="text/javascript"& ...

What is the reason for JQuery not generating a fresh div during every loop?

I'm currently facing an issue where jQuery seems to be combining all the image divs and description divs into one container div, rather than creating individual containers for each pair in my for loop. This is causing a disruption in the overall layou ...

Effect of Active or Focus on the HTML <ul> element

Check out this example of a UL tag: <ul style="list-style-type:none; padding:5px ; border:solid 1px #666666;"> <li>I am waiting </li> <li>I am waiting </li> <li>I am waiting </li> <li>I am wa ...

What is the best way to remove the excess space beneath a column in Bootstrap 5?

I made the changes as instructed, but when I view it on a mobile phone, the blue box and pink box are not aligned as I want them to be. I have attached a screenshot for reference, and I would like the mobile version to mirror the desktop version. I am uns ...

What steps can I take to ensure my site retains its appearance when minimized?

When I maximize my website, it looks great, but when I restore it down, the box on my site becomes distorted. I'm new to designing websites and struggling with this issue. Here's the code I've been using: .boxed { position: absolute ...

Stop the resizing of a div that contains an image when additional text is inserted into it

My website has a div that is centered and contains a picture. The div adjusts its height to fit the picture, but when I add text, the div unexpectedly resizes so that its height is taller than the picture itself. Here is an example: Html: <div class=" ...

jQuery is experiencing issues when attempting to add multiple rows to a table

I am currently working on building a function that takes an input and uses it to construct a grid. My main focus at the moment is getting the grid functionality up and running, but I've run into a strange issue. Despite searching for hours, all the so ...