The flex container is expanding larger than its parent container due to the height of its child elements

I have designed the following HTML element.

In this case, the remaining-height class is intended to be the remaining height of the container-div, which should be 100 - 15 = 85px. However, because the grand-child-div has a height of 200 px, the remaining-height div extends beyond the container-div.

How can I ensure that the remaining-height div reflects the correct height of the container-div (which should be 85px)?

Adding onto the previous comment, the remaining-height div should have a scroll inside it as the grand-child-div will have a greater height than the remaining-height.

<div class="container-div" style="height:100px">
  <div class="fixed-height">
  </div>
  <div class="remaining-height">
    <div>
      <div class="grand-child-div" style="height:200px">  
      </div>
    </div>
  </div>
</div>

Here is the CSS:

.remaining-height {
    flex: 1 1 auto;
    display: flex;
    flex-flow: column;
    background-color: yellow;
}

.fixed-height {
  height: 15px;
  background-color: green;  
}

Link to the example on JSFiddle

Answer №1

After reviewing the suggestions, the key solution is managing the overflow. By incorporating overflow: auto into .remaining-space, you can enable scrolling capabilities (particularly after configuring flex appropriately). For a visual representation, refer to jsfiddle.net/8yhd3tbz.

Answer №2

To enhance the element identified by the class: remaining-height, consider incorporating this code: height: calc(100% - 15px);

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

Bootstrap 5 and Vue 3 team up to create a stunning masonry layout

I've been struggling to find a proper solution for implementing a masonry layout in Vue 3 with Bootstrap. I tried using Bootstrap 5 cards with the Masonry CDN, but it resulted in squeezed and overlapping cards, failing to achieve the desired layout. I ...

What is causing this code to keep iterating endlessly?

I have a basic jquery script embedded in my HTML code that utilizes the cycle plugin for jQuery. The problem I'm facing is that when I interact with the slideshow using the "next" or "previous" buttons, it continues to loop automatically after that in ...

Is it possible to handle parsing of partial xml text within JavaScript using the newest version of Firefox?

After reviewing the responses, it appears that DOMParser may struggle with handling incomplete and not well-formed XML data. Considering most major browsers can manage faulty HTML source code, I am curious if there is a workaround to have the browser inte ...

Trouble with closing windows in the in-app browser on Android devices

Is there a method to successfully close the in-app browser? Despite window.close working on iOS devices, it is not effective on Android. I have experimented with alternatives like window.top.close and window.open("", "_self") window.close, but none have ...

Printing pages with Bootstrap without disrupting cards

My goal is to print a basic bootstrap page using window.print(). Here is what the page looks like (with multiple div.col-md-12 & cards) : <div class="overview"> <!-- Takes up entire screen width --> <div class="row"> <div ...

url-resettable form

Currently, I am working on an HTML form that includes selectable values. My goal is to have the page load a specific URL when a value is selected while also resetting the form back to its default state (highlighting the "selected" code). Individually, I c ...

Transitioning the image from one point to another

I am currently working on a unique single-page website and I have been experimenting with creating dynamic background animations that change as the user scrolls. Imagine my website is divided into four different sections, each with its own distinct backgro ...

Lack of animation on the button

Having trouble with this issue for 48 hours straight. Every time I attempt to click a button in the top bar, there is no animation. The intended behavior is for the width to increase and the left border color to change to green, but that's not what&ap ...

Sending Django Variable With Javascript

As a newcomer to Javascript, I am grappling with retrieving the value of a variable from my HTML form. My current code seems to be somewhat functional - I added an alert to test the logic and found that the else statement is working fine. However, I'm ...

The Troubles of Top Margins in CSS

Hey there, I'm a bit stumped on this issue. I've been trying to apply a 10px top margin to a paragraph inside a div, but instead of creating the space I want between elements, it just seems to push the whole containing div down by 10px. Here are ...

Creating a Masonry Gallery without any spacing between images

I'm looking to create a unique masonry gallery design that eliminates any gaps between images. I've experimented with various plugins like masonry and isotope, but they still leave gaps in the layout. Packery seems promising, however it tends to ...

Troubleshooting a display issue with Chrome's User Agent - Possible CSS solution?

After recently installing a WordPress theme, I am encountering an issue with a Facebook conversion box not displaying when accessing my site through Chrome. Interestingly, this problem does not occur when using Firefox. Upon inspecting the element in Chro ...

What is the best way to manage photos from your phone without having to upload them online?

I'm currently developing an application using AngularJS/Javascript, HTML, and CSS within a cloud-based environment on c9.io. My next task is to create and test an app that can access the phone's photo album, apply filters to images, and I'm ...

Experience the full functionality of Google Maps API without the need for jQuery or PHP with PanTo

I'm not a developer and I find myself stuck in the panTo() function. All I want is to execute this function with an if-else statement without having to reload the Google Map or using jQuery. <body> <div id="map"></div> <d ...

Utilizing Dynamic URLs and Transmitting Non-User Input Data from HTML to Python via Flask

After doing some research, I discovered that data can only be sent from input forms in HTML to Python using the POST method. I am now trying to find a way to pass a value (originally stored in a dictionary passed from Python) from HTML to Python. I have t ...

What is the reason for being unable to remove the event listener from a sibling element?

function show1() { console.log("ok1"); document.getElementById("a2").removeEventListener("click", delegate); } function show2() { console.log("ok2"); } function show3() { console.log("ok3"); } function delegate(event) { var flag = event.target ...

What steps can be taken to confirm that a comment posted on a specific post is genuine and related to that post?

Currently, I am immersed in the world of AJAX, PHP, and MySQL. Below is a snippet of my PHP code: if(isset($_GET['postTextComment'])){ // The text of the comment $htpc = htmlspecialchars($_GET['postTextComment']); // ID of ...

Strength Indicator for Passwords - Utilizing Html & Javascript/Ajax

Anyone know of a Password Strength Visualizer tool that provides a visual representation similar to Gmail's when creating a new account? I'm interested in displaying the password strength visually for users. If you have any source code you' ...

Insert code into the notes section of Pug

Need help inserting a script into a comment on Pug? I have two scripts that need to be added to my website: <!--[if lt IE 9]> <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script> <script src="http ...

Modifying Blocks in Prestashop: A Step-by-Step Guide

I'm looking to make some changes to the "categories" block in my left navigation column. Currently, it appears like this: https://i.sstatic.net/MpUD5.png I would like it to look like this by default: https://i.sstatic.net/fJTr8.png Here are the mod ...