What is the reason behind a flex child not expanding in Firefox when it has text-overflow and a scrollbar enabled?

I am facing an issue with a scrolling <div> that contains multiple items. These items have ellipsis set for overflow and are placed in an absolutely positioned container.

In Chrome and Edge, the items expand fully as there are no width restrictions. However, in Firefox, I encounter a problem where the items do not expand properly:

https://i.sstatic.net/bjBuz.png

Despite trying common solutions like setting the flex child's min-width or min-height to a fixed value, it does not resolve the issue in my scenario (refer to the code snippet).

The presence of the scrollbar seems to be causing the problem. When only two items are displayed and there is no scrollbar, the width remains unchanged.

Is there a workaround for this situation?

.content {
    position: absolute;
    top: 20px;
    left: 20px;
    height: 60px;
    display: flex;
    flex-flow: column;
    border: 2px solid red;
}
.scroller {
    flex-shrink: 1;
    overflow-y: auto;
    background-color: gold;
    min-width: 0;
    min-height: 0;
}
.item {
    text-overflow: ellipsis;
    overflow: hidden;
}
<div class="content">
    <div class="scroller">
        <div class="item">a12345</div>
        <div class="item">b12345</div>
        <div class="item">c12345</div>
        <div class="item">d12345</div>
    </div>
</div>

Answer №1

Do you think something like this is acceptable?

.content {
    position: absolute;
    top: 20px;
    left: 20px;
    min-width: 65px!important;
    height: 65px;
    display: flex;
    flex-flow: column;
    border: 2px solid red;
}
.scroller {
    flex-shrink: 1;
    overflow-y: auto;
    background-color: gold;
    min-width: 0;
    min-height: 0;
}
.item {
    text-overflow: ellipsis;
    overflow: hidden;
}
<div class="content">
    <div class="scroller">
        <div class="item" >a12345</div>
        <div class="item" >b12345</div>
        <div class="item" >c12345</div>
        <div class="item" >d12345</div>
    </div>
</div>

Answer №2

This issue with Firefox has been lingering since as far back as 2012 and unfortunately remains unresolved - https://bugzilla.mozilla.org/show_bug.cgi?id=764076.

It's not only a problem with flexbox, but also occurs with textareas. The temporary solution is to utilize scrollbar-gutter: stable for elements with overflow: auto. Although this may result in some unwanted white space when the scrollbar is not active, it's advisable to apply this workaround specifically for Firefox:

/* Firefox bug #764076 workaround */
@supports (-moz-appearance:none) {
  .scroller {
    scrollbar-gutter: stable;
  }
}

For further reference, check out the MDN documentation on scrollbar-gutter

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 an environment with Internet Explorer 8, is it possible to use CSS web fonts in the WOFF file format?

Looking to use web fonts on Explorer 8 but having issues with my woff file not being applied as the font for the webpage. Any solutions to this problem? ...

Mathematics - Determined the dimensions of an adjusted image size

Currently, I am implementing a basic mathematical method to crop an image. My approach involves utilizing the jQuery plugin called imageareaselect.js to overlay an adjustable layer on top of an image. By resizing this layer with the cursor and clicking a b ...

Image remains fluid within a static div without resizing

Any assistance would be greatly appreciated. I am currently facing an issue with a fixed div that is floating at the bottom of the screen, serving as ad space for the mobile version of a website. The problem arises when attempting to resize the browser win ...

Guide to positioning a link on the right side of a navigation bar

I am trying to achieve a specific layout using Bootstrap. I want to align the logout button to the right-hand side and have three modules (contact us, about epm, and modules) centered on the page. Can someone guide me on how to achieve this using Bootstr ...

Error with infiniteCarousel in Internet Explorer versions 7 and 8 when using jQuery

Hello everyone! I've run into a little issue with some jQuery code I'm using. It was working fine before, but after making several changes and improvements, I can't seem to figure out what the problem is. I keep getting JS errors in both IE7 ...

Tips for creating an array:

Currently, I am working on a project that involves using an array of objects. While I have a good understanding of what an array is and how to create an object, I am struggling with incorporating my student object into the array. In this project, each st ...

Calculating square roots in AngularJS

I'm building a basic calculator using a combination of HTML, CSS, and AngularJS. Overall, everything is functioning correctly, but I’m looking to incorporate a SquareRoot function into the calculator. Here’s a snippet of my code: function _solv ...

What is the best way to maintain the standard height behavior of a fixed element?

I'm new to web development and currently working on my first website using only HTML, CSS, and JavaScript. I encountered an issue with the height of a fixed block element. When the user clicks on the "Contact us" link, a box containing contact informa ...

I'm attempting to slightly adjust the alignment of the text to the center, but it keeps causing the text to shift

I am facing an issue where I want to slightly center text, but whenever I add just 1px of padding-left, it moves to a new line. In my layout, I have 2 columns each occupying 50% width of the screen. One column contains only a photo while the other has a ba ...

Why does the width/height of an input and a select appear differently on every browser I've tested?

I am puzzled by the fact that, despite resetting their properties, the width and height of both the input and select boxes are different (you can see for yourself on this fiddle): HTML <div class="myDiv"> <input class="myInput&q ...

What is the best way to position a Radio group next to a TextField in Material UI

I've been through the documentation, but I'm struggling to understand how styling works in Material UI. Currently, I have a radio-group component set up like this: import React from 'react' import Radio from '@material-ui/core/Rad ...

Issue with sticky-navigation not functioning properly in conjunction with Bootstrap navbar

I'm struggling with getting the sticky-top function to work properly. To work around the issue, I ended up writing some messy javascript code, but I'm hoping someone might have a better idea. My goal is to have the element stick to the top of the ...

What is the best way to center align all elements using a wrapper in CSS grid?

I am working on designing a layout that looks like this: https://i.sstatic.net/jAaXL.jpg I have set the wrapper as a class and aim to center everything on the screen. Aside from the wrapper, I also want to make the text and form equal sizes. Here is th ...

Utilize a single image to encompass the entire background/theme

As a beginner, I am eager to learn how to use html and css. I understand the importance of being able to style an entire webpage in order to prevent issues like page overload or cache problems. Are there any easy-to-understand examples available for begi ...

Optimizing CSS With jQuery During Browser Resize

I am currently facing an issue with recalculating the height of the li element during window resizing or scrolling. Strangely, on page load, the height is no longer being re-calculated and set to the ul's child height. Here is the code I have written ...

What is the best way to navigate to the bottom of a website, similar to a "back to top

I have implemented a code snippet on my blog to go "Back to top" using a combination of HTML, CSS, and JavaScript. Now I am looking to add functionality for the opposite action, which is to "Go to Bottom". The code for going back to the top looks like this ...

Using TailwindCSS with Vite in a vanilla JavaScript project: A step-by-step guide

As a beginner, I feel like I'm losing my mind trying to figure this out. I've watched countless tutorials and read through numerous documents, but still can't seem to get it working. Does anyone have any advice on how to successfully integra ...

Leveraging HTML5's local storage functionality to save and manage a collection of list elements within `<ul>`

I need help with saving a to-do list in HTML so that it persists even after refreshing the browser. Can anyone assist me? html <!DOCTYPE html> <html> <head> <title>My To-Do List</title> <link rel="sty ...

Trigger the underlining effect to appear beneath the link when it is hovered

I need assistance in creating an effect where a line shoots across below a link when hovered over and disappears when the mouse is not hovering. I hope my description makes sense, please let me know if it doesn't. I suspect that using an actual underl ...

Incorporate pug and sass into your React project for a more

Are pug/jade and sass compatible with react? I enjoy organizing my code by separating files, and the functionality that sass and pug provide is great for this purpose. Is there a way to integrate pug and sass into a react project? Pug example: doctype ...