flex child moves outside parent when available space shifts

My dilemma involves a flex container (A) containing two or more flex items stacked in a column. The top flex item (B) is a Bootstrap Collapse panel, while the bottom item (C) consists of two horizontal divs (D and E). The problem arises when the collapse panel (B) expands, causing the bottom item (C) to extend beyond the boundaries of container A instead of shrinking to fit within it. I attempted to rectify this by incorporating 'overflow-y:scroll;' for D and E if needed, but encountered an issue with an unnecessary scroll bar appearing on the right side of C.

Illustrated below:

+------------------------+
| A: Flex Container      |
| +--------------------+ |
| | B: Collapse Panel  | |
| +--------------------+ |
| +--------------------+ |
| |  C: Bottom item    | |
| | +-------+ +------+ | |
| | | D     | |  E   | | |
| | +-------+ +------+ | |
| +--------------------+ |
+------------------------+

You can view the code on my CodePen at this link. Here is the sample code provided:

<html>

<head>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</head>

<body>

  <div class="container" style="display: flex; flex-direction: column; height: 260px; border: 10px solid red;">
    <div class="panel-group">
      <div class="panel panel-default">
        <div class="panel-heading">
          <h4 class="panel-title">
          <a data-toggle="collapse" href="#collapse1">Collapsible panel (section B)</a>
        </h4>
        </div>
        <div id="collapse1" class="panel-collapse collapse">
          <div class="panel-body">Panel Body</div>
          <div class="panel-footer">Panel Footer</div>
        </div>
      </div>
    </div>
    <div style="background-color: yellow; height: 100%; display: flex; flex-direction: row;">
      <div style="width:40%; background-color: lightgreen; overflow-y: scroll; ">
        Section D
        <ul>
          <li>1</li>
          <li>1</li>
          <li>1</li>
          <li>1</li>
          <li>1</li>
          <li>1</li>
          <li>1</li>
        </ul>
      </div>
      <div style="width:50%; background-color: pink; overflow-y: scroll;">Section E</div>

    </div>
  </div>

</body>

</html>

Despite searching for solutions online, I could not find one that addresses this particular issue specifically. However, as is often the case, I was able to discover the answer while formulating the question, which I will share below.

Answer №1

To make the scroll bar activate, I discovered that applying overflow-y: hidden; to the bottom item (C) was the trick. It seems that vertically clipping a div with overflow-y:scroll does the job.

<html>

<head>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</head>

<body>

  <div class="container" style="display: flex; flex-direction: column; height: 260px; border: 10px solid red;">
    <div class="panel-group">
      <div class="panel panel-default">
        <div class="panel-heading">
          <h4 class="panel-title">
          <a data-toggle="collapse" href="#collapse1">Collapsible panel (section B)</a>
        </h4>
        </div>
        <div id="collapse1" class="panel-collapse collapse">
          <div class="panel-body">Panel Body</div>
          <div class="panel-footer">Panel Footer</div>
        </div>
      </div>
    </div>
    <div style="background-color: yellow; height: 100%; display: flex; flex-direction: row; overflow-y:hidden;">
      <div style="width:40%; background-color: lightgreen; overflow-y: scroll; ">
        Section D
        <ul>
          <li>1</li>
          <li>1</li>
          <li>1</li>
          <li>1</li>
          <li>1</li>
          <li>1</li>
          <li>1</li>
        </ul>
      </div>
      <div style="width:50%; background-color: pink; overflow-y: scroll;">Section E</div>

    </div>
  </div>

</body>

</html>

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

Can someone tell me where I can locate the CSS file once I've finished using Scene Builder?

Currently, I am working on my database project using Scene Builder. I have applied some CSS styling and would like to locate the CSS file in order to attach it to my IntelliJ project for further code editing. Can anyone guide me on where to find the CSS ...

Set the height of the unordered list (ul) to be

I came across a design on Facebook that resembles a timeline, but I am having trouble adjusting the height of the ul element. <ul class="timeline">...</ul> I want the line in the middle to fill the height of the page even when there is less c ...

Typeahead in Angular is failing to function properly after using the $compile method

I have made some adjustments to the popover directive in order to include files and $compile them. While I've managed to make ng-repeats function properly, I'm facing issues when trying to add a typeahead feature. angular.module("app").directive ...

Asynchronously load an AngularJS controller from AJAX without altering the route

I am looking to dynamically load an Angular controller after making an AJAX call that generates a new view in HTML. Here is the setup I currently have: Example of a View: HTML Snippet From AJAX <!-- CVS Pharmacy Extracare - Add View --> <d ...

Creating a connection between my .html and .ejs files: A step-by-step guide

I have successfully created a pair of HTML files - index.html & contact.html. Within these files, I have implemented a navigation bar that allows for seamless transition between them. Recently, I delved into the realm of retrieving APIs and crafted an app ...

Issues with fonts in Google Chrome Version 32.0.1700.76 m

After recently updating my Google Chrome browser, I noticed that some of the fonts are not displaying correctly. Interestingly, they appear fine on other browsers, but the issue only seems to occur in Chrome v32.0.17...76 m. The fonts I used were "Open Sa ...

Comparison of Chrome's compatibility with Bootstrap and Edge

Firefox Safari I am facing an issue that seems obvious, but I am unable to pinpoint the exact cause. It just doesn't seem right for no apparent reason. is the website in question. I have tried various troubleshooting methods such as inspecting th ...

What is the deal with CSS relative magnification?

I am currently utilizing a PHP styleswitcher along with alternate stylesheets in an attempt to replicate the functionality of browser zoom (done using keyboard shortcuts cmd-plus or ctrl-plus). At the moment, when clicking on the "zoom in" graphic, it is ...

Exploring the Images directory

I hate to admit it, but I'm really struggling with this question. It's frustrating and I've searched everywhere for an answer. Currently, I'm using WAMP on Localhost with PHPstorm. The issue I'm facing is accessing the images di ...

Using jQuery to arrange information from an API into a table

Currently, I am in the process of learning jQuery as it is a new concept for me. I have attempted to make a request to an example API and received an array of objects that need to be listed in a table. However, I am facing difficulty in sorting it within t ...

Do AngularJS routes allow the use of special characters in URLs?

Issue at hand: Every time I enter http://localhost:53379 in the browser, it redirects me to http://localhost:53379/#/. Why is the /#/ being added? angular .module('app', ['ngRoute', 'ngStorage']) .config([&apo ...

What is the reason for the improper setting of the div position?

Welcome to the interactive Pointer Pin application! The red-bordered box is where you can drop your Pointer Pins. This area has a background image set. The blue-bordered box is where you can drag various Pointer Pins from. These pins can be dropped into ...

Using Jquery and CSS to create a sleek animation for opening a div box container

Designed an animation to reveal a div container box, but it did not meet the desired criteria. Expectations: Initiate animation horizontally from 0% to 100%. Then expand vertically to 100% height. The horizontal animation from 0% to 100% is not visible ...

Highlight all the written content within the text box

I'm struggling with a piece of code that is supposed to select all the text inside an input field: <input id="userName" class="form-control" type="text" name="enteredUserName" data-ng-show="vm.userNameDisplayed()" data-ng-model="vm.enteredUs ...

Is there a way to adjust the placement of the h1 tag using the before pseudo-element?

I'm looking to place an image on the left side of each h1 tag. I've been attempting to utilize the before pseudo element for this task. The issue arises when there is no content, causing the before pseudo element to overlap with the h1 tag. How ...

issues with background image alignment in css

I attempted to add a sticky background to a div, which was successful. However, I am encountering an issue where the background does not stretch enough during scrolling. Below is the CSS code I used to apply the background, along with screenshots displayin ...

The connection between an HTML form and PHP is not being established

variable-passing.php `<form method="post" action="variable-catching.php"> <input type="text" name="name1"/><br/> <input type="text" name="name2"/><br/> <input type="text" name="name3"/><br/> <input type="te ...

Say goodbye to using 'jQuery .load()' with <img> elements inside <a> tags

I have a static HTML page and some other files with the same structure but different content. <div id="textRed" class="scrollbar"> <h1>Header</h1> <p>Lorem Ipsum</p> <a href="images/image1.jpg" data-lightbox ...

Positioning a div element within a list item using CSS

Currently, I am in the process of constructing a megamenu. In this setup, there is an unordered list that is positioned relative to its parent container. Within this list, there are individual items that contain links along with separate div containers th ...

Creating a dynamic background color that pulses with animation

I recently created a script to animate the menu li element when hovering over the corresponding a element. Everything is functioning as expected, but now I'm looking to enhance the effect by having it continue as long as the mouse remains over the a e ...