Container with flexible layout and scrolling overflow

I am having issues with a flex container div in Firefox. How can I resolve this problem? Here is an example of my code:

<div id="holder">
   <div id="content"></div>
</div>

Here is the CSS for the element:

#holder {
   border: 1px solid #eee;
   display: flex;
   flex-direction: column-reverse;
   justify-content: flex-start;
   overflow: auto;
}
#content div {
   height: 110px;
   border-top: 1px solid black
}

And here is the JavaScript that dynamically adds a div into the content:

<script type="text/javascript">

    var C = document.getElementById('content');
    var H = document.getElementById('holder');
    var rowNum = 0;
    setInterval(function() {
        var row = document.createElement('div');
        row.innerHTML = 'Row #' + rowNum++;
        C.appendChild(row);
    }, 2000);

    H.addEventListener('scroll', function(e) {
        var bottomDiff = C.getBoundingClientRect().bottom - 
        H.getBoundingClientRect().bottom;

        var oldScrollTop = H.scrollTop;
        H.classList.toggle('manualScroll', bottomDiff > 0);
        if (bottomDiff > 0) {   
            H.scrollTop = oldScrollTop; 
        }
    });
</script>

Answer №1

Upon reviewing your code, I noticed that you need to include overflow:auto in the #content element rather than the #holder element.

var C = document.getElementById('content');
    var H = document.getElementById('holder');
    var rowNum = 0;
    setInterval(function() {
    var row = document.createElement('div');
    row.innerHTML = 'Row #' + rowNum++;
    C.appendChild(row);
    }, 2000);

    H.addEventListener('scroll', function(e) {
    var bottomDiff = C.getBoundingClientRect().bottom - 
    H.getBoundingClientRect().bottom;

    var oldScrollTop = H.scrollTop;
    H.classList.toggle('manualScroll', bottomDiff > 0);
    if (bottomDiff > 0) {   H.scrollTop = oldScrollTop; }
    });
#holder {
   border: 1px solid #eee;
   display: flex;
   flex-direction: column-reverse;
   justify-content: flex-start;
   overflow: auto;
}
#content div {
   height: 110px;
   border-top: 1px solid black
}
#content {
overflow:auto
}
<div id="holder">
   <div id="content"></div>
</div>

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

Arranging data into columns using HTML and CSS

I'm currently working on a CSS solution to organize various elements like buttons and text in a tabular column format. My main challenge lies in controlling the layout effectively, especially since CSS columns are not compatible with IE9 and earlier v ...

Telerik Border RadCheckBox

Is there a way to get rid of the black border that shows up when the checkbox is clicked in Bootstrap 4.4.1? Check out this image for reference ...

Aligning CSS tables vertically poses a challenge for me

Although I usually prefer HTML tables for their ease and speed, I am attempting to follow best practices and use CSS tables instead. A new issue has arisen... I am working on an HTML page with tabular data in CSS format, containing 3-4 pieces of data acr ...

What is the best way to showcase an image using CSS on my personal computer?

It's a bit embarrassing to admit, but I'm learning some new concepts and struggling with this one. On my computer, there's a folder named Test that contains an index.html file, a CSS subfolder with an index.css file, and an images subfolder ...

What's preventing me from invoking this object's function through an inline anchor?

CSS: <div class="box"> <p>This is a box</p> </div> Javascript: var box = { content : (function() {return ("This is the content of the box")}) }; alert("Box content: \n" + box.content()); $("output").text( +"<br/ ...

Adding a gradient to enhance an SVG chart

Hey there! I'm currently experimenting with Plotly to create some awesome charts, and I've been trying to figure out how to give my area-charts a gradient instead of the usual fill with opacity. This is how I typically build my graph: Plotly.ne ...

Numerous JavaScript Buttons with Variable Assignments

Currently in the early stages of learning JavaScript, I have a query regarding how to assign different functionalities to various buttons. While I have successfully implemented a function for one button, I am unsure of how to manage a second button with ...

I am having trouble toggling radio buttons in React

class VoiceSelector extends Component { constructor(props){ this.handleCheck = this.handleCheck.bind(this); } state={ voices : [ {"Voice":"Indian English Female Voice 1"}, {"Voice":&qu ...

Check if the data-indices of several div elements are in sequential order using a jQuery function

Is there a way to implement a function in jQuery-ui that checks the order of div elements with data-index when a submit button is pressed? I have set up a sortable feature using jQuery-ui, allowing users to rearrange the order of the divs. Here is an exam ...

Python, Selenium, and PyVirtualDisplay headache: Struggling to interact with a web element

My web crawler for Twitter is encountering an issue on my new computer where the click functionality has stopped working. It logs into Twitter, navigates to the following page, and collects information from all my followers by clicking on the gear icon. I ...

How to align label and input field horizontally in Bootstrap 4

When designing a form in Bootstrap 4, there are specific requirements that need to be met: 1) The screen needs to be split into two parts. (ID & Age one part, Name & College another part.) To achieve this, I am utilizing class="container", is th ...

Transforming Toggle down div into a sliding animation from right to left using javascript

Hey there, I have two divs - one named basic and the other advanced. There's a button to show the advanced div. Currently, when I click on the button, it toggles down. However, I would like it to slide from right to left instead. Here's the HTML ...

"Incorporate a placeholder into Bootstrap's selectpicker for enhanced user

I have been working on a bootstrap selectpicker and I am trying to add a placeholder text inside the search input area that says Search here. However, my current methods do not seem to be effective. I attempted to use this script, but it did not produce t ...

Codeception is unable to interact with an element that it recently encountered

Greetings to the wonderful users of Stackoverflow, Currently, I am in the process of creating acceptance tests using Codeception with Selenium as the WebDriver module. I have encountered an issue while trying to verify the existence and functionality of o ...

Utilize jQuery to create a dynamic image swapping and div showing/hiding feature

I'm having trouble implementing a toggle functionality for an image and another div simultaneously. Currently, when the image is clicked, it switches to display the other div, but clicking again does not switch it back. Can someone please advise on wh ...

Automatically align a Div to the right within an ngFor directive in an Angular 6 application

<div class="row"> <div class="col-lg-4 col-xs-6" *ngFor="let client of clients;index as i"> <!-- small box --> <div class="small-box bg-dashboard-box" > <div class="inner"> <div class="text-black"> ...

Personalize your Native Base tab design

Recently, I've delved into the world of React Native and now find myself in need of assistance with customizing my tabs. Utilizing advanced tabs by Native Base, I aim to transform this: https://i.stack.imgur.com/xhNwP.png Into something more akin ...

What is the best method for efficiently wrapping contents within a div container?

On the website cjshayward.com/index_new.html, there is a div wrapped around the content of the body, which is approximately 1000 pixels wide. In Chrome and Firefox, the wrapper works perfectly for the top section of about 100 pixels. Further down the page, ...

Expand the dimensions of the file upload field to make it taller and wider

I am trying to create a file upload field within a transparent div sized at 150px x 150px. The goal is for the file dialog box to pop up when any part of the div is clicked, allowing the user to select a file for upload. Despite my attempts, I haven't ...

Need help modifying a UseStatus to target an axios post response efficiently?

Hey there, back again with a head-scratcher I've been dealing with all day. Almost done with a contact form, just stuck on an animation concept that involves three steps: 1. Prompting the user to contact 2. Making the waiting process user-friendly ...