What causes the difference in behavior of 'flex-grow' between Chrome and Firefox/Edge?

Trying to create a webpage with a fixed height 'header' div followed by a 'content' div below it. The content div contains various other divs with actual page content, generating dynamically through PHP resulting in varying heights for different screens and users.

If that explanation is unclear, check out what I've accomplished so far: https://codepen.io/anon/pen/ZJPgWm (the code might look messy as it's a quick imitation of my real project).

#main {
    width: 90%;
    min-width: 400px;
    max-width: 1200px;
    height: calc(100vh - 10px);
    margin-left: auto;
    margin-right: auto;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

#head {
    background-color: blue;
    font-size: 3vh;
}

#content {
    background-color: red;
    flex-grow: 1;
    display: flex;
}

#left {
    width: calc(16% - 6px);
    float: left;
    background-color: green;
}

#inner {
    font-size: 10vh;
    flex-grow: 1;
    width: calc(84% - 6px);
    float: left;
    margin-left: 8px;
    margin-bottom: 10px;
    flex-grow: 1;
    overflow-x: hidden;
    overflow-y: auto;
    background-color: yellow;
}
<body>
  <div id="main">
    <div id="head">
      Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
    </div>
    <div id="content">
      <div id="left">
        Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
      </div>
      <div id="inner">
        <p>
          Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
        </p>
      </div
    </div>
  </div>
</body>

The issue arises on Firefox and MS Edge where the overflowing content in #inner div gets cut off instead of showing a scroll bar like in Chrome. Reason appears to be in how the browsers handle height setting within the elements near its boundaries.

Looking for a solution that makes all browsers behave like Chrome. Also seeking clarification on which browser behavior is correct and the differences between them.

Aiming to avoid using JavaScript if possible. Any guidance or assistance is appreciated.

Answer №1

When working with nested flex items, it's important to note that by default, a flex item has a min-height of auto, meaning it won't shrink below the size of its content. To allow a flex item's child to overflow properly, you may need to specify a min-height: 0; in your CSS rule.

By incorporating this adjustment, your layout will function as expected. See the sample code snippet below for reference:

#main {
  width: 90%;
  min-width: 935px;
  max-width: 1600px;
  height: calc(100vh - 90px);
  margin-left: auto;
  margin-right: auto;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

#head {
  background-color: blue;
  font-size: 20px;
}

#content {
  background-color: red;
  flex-grow: 1;
  display: flex;
  min-height: 0;
}

#inner {
  font-size: 60px;
  flex-grow: 1;
  overflow-y: auto;
}

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

Have you opened the DIV in a separate tab yet?

Hey there! So, I've got a question for you. I've got 4 little DIV's with text inside them. At the bottom of each DIV, there's a link that says "show more". When I click on that link, I want the respective DIV to open in a new tab. Ho ...

Combining a left div, a right div, and a center div to equal 100% width. What is the best

I currently have a main div and three additional divs contained within it: <div id="container" style="width:100%;"> <div id="left" style="width:201px; float:left;"> .... </div> <div id="centre" st ...

Google Extension PHP Plugin

Is it feasible to integrate a PHP file into a Google Extension for Chrome? I've been exploring the idea of creating an extension and most resources only mention HTML, CSS, and JavaScript. Any guidance on using PHP in the extension would be highly valu ...

Is there a way to eliminate the menuArrow from a Select widget in gwt-bootstrap3?

In my current project, using gwt-bootstrap3, I have been attempting to conditionally remove the menu arrow from a Select box. I have experimented with various methods such as: <select:Select ui:field="fieldName" name="fieldName" b:id="fieldName" showM ...

The vertical drop-down menu is displaying and functioning incorrectly

My vertical submenu is positioned correctly, but the links are overlapping on top of each other. The submenu doesn't hide when hovering over the main menu, but it does hide when hovering outside the menu. I'm unsure of what changes or additions t ...

Stop a looping animation keyframe in CSS and make it animate back to the beginning

I am facing an issue with a looping animation that rotates a square. Whenever I remove the class responsible for the animation, the square immediately returns to its initial position. My objective is to animate the square back to the starting position upo ...

The response contains a JSON object with the values [object, Object]

I am attempting to showcase JSON data in an HTML table. Here is the code I have been using: <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script> $(document).ready(function(){ ...

When the image is scrolled into position, the parallax animation experiences a delay

I am experiencing a delay in the parallax animated effect of 3 images. This issue was correctly pointed out by @Roko C. Buljan. Is there a way to fix this? My code is visible here - but the effect only works under 670px (without going into full screen mo ...

Two Bootstrap modals with customized maximum width and height dimensions

I'm working on designing 2 modals for a Bootstrap themed webpage. https://i.sstatic.net/N4gNl.png One of the modals, the wider one, has been successfully created. Below is the CSS code: .modal-dialog { width: auto; height: auto; positio ...

What is the best way to align icons in the center alongside text or paragraphs using react?

I'm struggling with centering my icons like <GrTools size="30px"/> next to my text. It's causing some alignment issues with my styled components. Here is my JavaScript: <div id='paragraph' className="container"> ...

Transforming the appearance of a Formik Multi-Select component to resemble a Material-UI select widget

I need help styling the Formik select component for multiple selections. I want to make it look like a Material-UI select with some specific height, length, and rounded borders. Any advice on how to do this using Material-UI styling or my own custom stylin ...

Maintaining Flexbox layout without triggering item re-rendering for a new container

This is the unique layout I'm aiming to create: I am facing a challenging flexbox layout that needs to be implemented. One of the items in this layout is a Webgl player, which cannot be conditionally rendered due to the restarting issue it may cause. ...

Tips for keeping an image at a fixed size within a grid, even when the browser window is resized

As a newcomer to front end coding, I am currently working on a practice website to familiarize myself with the code. One issue I am facing is related to using a bootstrap grid with an image in the left column. I want to prevent the image size and position ...

transforming html into json using PHP

I am encountering an issue where I am making a PHP request and receiving the response in HTML format. How do I go about converting this response to JSON format? case 'getzipcode': $CITY= @$_POST['city']; $STREET= @$_POST['street& ...

What is the best way to customize Bootstrap for optimal display on my mobile device?

Despite creating an application that should be responsive, it seems to only work well in the browser. When testing it on a phone, the screen doesn't adjust properly. Here is the site in question: I'm puzzled as to what I may have overlooked. An ...

Guide to setting up a search function with class name filtering

I am currently managing a website with multiple items, each represented by individual div elements. While all items share one common class name, they also have several other class names serving as tags to differentiate them (some tags may overlap between d ...

Adding an event listener to detect left or right mouse clicks - using onclick doesn't capture right clicks

I'm currently in the process of applying for an Internship through this Internship Link One thing that caught my attention right away is the issue with uploading or pasting a cover letter. When attempting to upload or paste a cover letter, it redirec ...

React automatic scrolling

I am currently working on implementing lazy loading for the product list. I have created a simulated asynchronous request to the server. Users should be able to update the page by scrolling even when all items have been displayed. The issue arises when ...

The CSS scale property is not working as expected when used in a React.js application, specifically

working environment ・next.js ・react ・typescript https://www.youtube.com/watch?v=ujlpzTyJp-M A Toolchip was developed based on the referenced video. However, the --scale: 1; property is not being applied. import React, { FunctionComponent ...

3 Typeahead elements within a div with horizontal overflow

I have a container with the class 'table-responsive' that has overflow-x set to 'auto'. Within this container, there is an input field with typeahead. When I receive results to populate the typeahead, they appear within the container. ...