difference in flex-shrink behavior between Firefox and Chrome

Why does this code sample render differently on Firefox than on Chrome? Is this a browser bug, and if so, which browser is rendering per spec?

If there is a bug report available, I would appreciate a link to it.

Currently, adding flex-shrink: 0 to the navbar in this example solves the issue for my needs. However, I am curious if this fix will still work in the future once the bug is addressed...

#fixed {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
}

#tall {
  height: 300%;
}

.outline {
  outline: 1px solid red;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" />

<div id="fixed" class="d-flex flex-column">
  <nav class="navbar outline">
    <a class="btn btn-secondary">Button</a>
  </nav>
  <div id="tall"></div>
</div>

Answer â„–1

flex-shrink inconsistencies between Firefox and Chrome

A difference exists, but it seems that flex-shrink is not the root cause.

Could this be due to a browser bug, and if so, which browser follows specifications correctly?

It is not a bug per se. It appears to be more of an intentional deviation from the specifications, applied by Chrome.


flex-shrink: 1

The initial setting for a flex container is flex-shrink: 1, as outlined in the flexbox specification. This allows flex items to shrink to prevent overflowing the container.

Both Chrome and Firefox follow this guideline. Checking the default styles in developer tools confirms that both browsers apply flex-shrink: 1 to flex items.

For more information, refer to: How does flex-shrink factor in padding and border-box?


min-height: auto

In a column-direction flex container, the default setting for items is min-height: auto. In a row-direction container, items have min-width: auto. This sets the minimum size of a flex item to its content size or specified length along the main axis.

To learn more, visit: Why don't flex items shrink past content size?


Your Code

You have a column-direction flex container with two items: .navbar and #tall. Both Chrome and Firefox set these items to flex-shrink: 1 and min-height: auto by default. Inspection via dev tools confirms compliance with the spec.

The discrepancy arises here: The #tall item has height: 300%, significantly taller than the container. With flex-shrink: 1, overflow should be prevented. However, due to min-height: auto, items cannot shrink below their content height.

This behavior works in Firefox but not in Chrome. Why does the .navbar item in Chrome shrink below its button content when squeezed by #tall?


Firefox

The #tall element, with height: 300%, can't overflow due to flex-shrink. Its sibling, .navbar, must also shrink responsibly. Unable to go below content size because of min-height: auto, everything aligns with the spec.


Chrome

In Chrome, like in Firefox, #tall adheres to flex-shrink, preventing overflow. However, while .navbar should avoid shrinking beneath content size with min-height: auto, it does so anyway. Why?


Interventions

An intervention occurs when a user agent modifies standardized behavior for better user experience.

source: https://github.com/WICG/interventions

Referencing my answer here:

Since around 2017, Chrome might revert to min-width: 0 / min-height: 0 defaults, or dynamically apply them based on certain criteria (possibly an intervention). This shift could explain why layouts differ between Chrome, Firefox, and Edge.

Hence, the issue you face likely results from intended divergences rather than bugs. Firefox seems to comply closely with specifications.


Key Points

Note that my insights into Chrome's internal functioning are conjectural. I presume Chrome adjusts min-height based on personal observations—it's speculative. Such undocumented behaviors may change unpredictably over time.

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

Is it possible to change the background color of a Bootstrap button using CSS overrides?

Desired Outcome https://i.sstatic.net/EjEXG.gif Actual Result https://i.sstatic.net/BmXYG.gif The goal is to toggle the red-background class, so that when hovering over the button-bullet, its background-color changes to #FCC1C5. Avoiding the use of .b ...

Modify the Primevue Class p-accordion-header only under certain conditions

I'm currently facing a challenge with customizing the styling of the primevue component class p-accordion-header based on the status of the rendered component determined by the variantNumber. Here's a snippet of my code: <Accordion :multiple= ...

HTTP GET request not updating data

I'm experimenting with AngularJS and trying out some examples: Here's the HTML code snippet: <html ng-app="myApp"> <body ng-controller="JokesController"> <h1>{{ joke }}<h1> </body> </html> A ...

How can I deactivate Bootstrap specifically within a certain block of content?

Is there a way to deactivate Bootstrap within a specific section? I want the styles from Bootstrap's CSS file to be overridden inside this div. ...

Exploring the basics of Three.js: a step-by-step guide using a shadertoy example on transforming patterns with objects

Check out this snippet, inspired by the second live example found at : html, body { height: 100%; margin: 0; } #c { width: 100%; height: 100%; display: block; } <canvas id="c"></canvas> <script type="module"> // Three.j ...

Adjust the contents of a DIV depending on which Toggle button is selected

When a user clicks on either "Twin Bed" or "King Bed", the content inside the "demand-message" should change to either "high demand" or "Only ??? rooms left". The ID will remain the same for both buttons due to existing logic. However, the message display ...

The clickable areas for the href and onclick functions are extremely small and positioned inaccurately on the screen

The code below is supposed to load an image of a 'close window' button that should be clickable. However, when the page loads, the clickable area is only a couple of pixels wide and a pixel or two high, positioned just below or above the center o ...

Creating background color animations with Jquery hover

<div class="post_each"> <h1 class="post_title">Single Room Apartments</h1> <img class="thumb" src="1.jpg"/> <img class="thumb" src="1.jpg"/> <img class="thumb" src="1.jpg"/> <img class="thumb last" ...

"Redirecting to an HTML page from the POST method is not supported in the Flask backend and Vanilla JS frontend setup

Utilizing the selected dropdown value from the frontend to perform calculations on the backend, resulting in an HTML page being returned. It's worth noting that no response is needed from the POST method, such as using return jsonify. Currently, I am ...

I am unable to load any HTML files in my VueJS iframe, except for the index.html located in the public

Within the template of my vue component, I am utilizing the following code: <iframe width="1000vw" height="600vh" src="../../public/myHtmlFile.html"></iframe> Unfortunately, the file specified in the src attribut ...

Height problem with Semantic UI cards in Chrome on Windows

Encountering an issue specific to Chrome on Windows where the height of my .card elements is not displaying correctly. The height appears to be either too much or too little, causing the problem shown in the screenshot below. This issue seems to be isolate ...

Showcasing Portfolio Work in a User-Friendly Mobile Design

Currently revamping my portfolio website and looking for ways to optimize the display of my personal projects. I have a card-like interface in place that works well on desktop but only shows one project at a time on mobile devices. Seeking solutions to imp ...

Discreet elements are not functioning

It's frustrating that everything in the 'wrapper' won't stretch to fit properly, instead staying at a fixed height. I'm trying to make the 'sidebar' and 'content' inside the area have the same height at all time ...

The appended button remains unresponsive when clicked

After conducting extensive research, I have come across numerous questions on overflow regarding a specific issue, but none of the solutions seem to work. The problem revolves around a button that appears on the page when another element is clicked. The u ...

Resetting the "clear: both" property for the nth-child element when multiple nth-child elements are being inherited

Currently utilizing CSS (specifically SCSS) to style the same element on various media sizes - A, B, and C. Utilizing the following for A: &:nth-of-type(2n+1) { clear: both; } For B: &:nth-of-type(3n+1) { clear: both; } Finally, for C: ...

Disappearing Into the Background Excluding Specific Divs

I have a dilemma with fading in and out a background image using jQuery fadeIn and fadeOut. The issue arises because my wrapper div contains elements such as sidebar and navigation that are positioned absolutely within the wrapper div, causing them to also ...

Adjust background image size to fit the dimensions of the foreground content

I have a div where an image and content are inside. I am trying to make the background image adjust its size based on the content within it, rather than showing the full image size with empty space. My current styling uses flexbox: .section { height: ...

What is the correct way to call upon Bootstrap's CSS that was obtained through a Gradle dependency?

I'm having trouble referencing the Bootstrap library from the 'External Libraries' section in my project. In my build.gradle file, I included: compile group: 'org.webjars', name: 'bootstrap', version: '3.3.7' ...

Resolving the Complete Cover Background Image problem

My current website has a full cover background image implemented using the following code: #back{ /* #back is a div */ position:absolute; -webkit-background-size: cover; -moz-background-size: cover; -o-background-size: cover; backgroun ...

Creating a dynamic list structure using <ul> and <li> tags in a CSHTML ASP file

I am aiming to design a visually appealing structure using ul li for categories. Each line of the structure should consist of three elements: <li> <ul class='kwicks kwicks-horizontal'> <li></li><li></l ...