Issues with scrolling divs not properly reaching the bottom of the content

I am facing an issue with 2 scrolling divs (outlined in red) that refuse to scroll to the bottom. I cannot seem to pinpoint what needs to be adjusted to resolve this problem.

The thick outlined box represents a simulated browser window.

View the code here

HTML

<div class="container">
    <div class="header"></div>
    <div class="sidebar"></div>
    <div class="main">
        <div class="detail-container">
            <div class="top-info"></div>
            <div class="items-container">
                <div class="item blue"></div>
                <div class="item orange"></div>
                <div class="item blue"></div>
                <div class="item orange"></div>
            </div>
        </div>
        <div class="main-container">
            <div class="main-header"></div>
            <div class="main-content">
                <div class="item grey"></div>
                <div class="item purple"></div>
                <div class="item grey"></div>
                <div class="item purple"></div>
                <div class="item grey"></div>
                <div class="item purple"></div>
                <div class="item grey"></div>
                <div class="item purple"></div>
            </div>
        </div>
    </div>
</div>

CSS

.container {
    height: 500px;
    width: 500px;
    border: solid 3px black;
    overflow: hidden;
}

.header {
    height: 25px;
    background-color: #333;
    right: 0;
    left: 0;
}

.sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    width: 75px;
    margin-top: 35px;
    border: solid 1px grey;
}

.main {
    height: 100%;
    padding-left: 75px;
}

.main-container {
    width: 65%;
    height: 100%;
}

.main-content {
    height: 100%;
    overflow-y: scroll;
    border: solid 1px red;
}

.main-header {
    height: 20px;
    border: 1px solid black;
}

.detail-container {
    float: right;
    width: 35%;
    height: 100%;
    border: solid 1px grey;
}

.top-info {
    padding: 75px 0;
}

.items-container {
    height: 100%;
    overflow-y: scroll;
    border: solid 1px red;
}

.item {
    padding: 100px 0;
} 

.blue { background-color: blue; }
.orange { background-color: orange; }
.grey { background-color: grey; }
.purple { background-color: purple; }

.content {
    width: 65%;
    height: 100%;
}

Answer №1

The container has a fixed height and overflow set to hidden, causing the divs that exceed the height to be hidden.

Here is an alternative solution:

.container {
    height: 500px;
    width: 500px;
    border: solid 3px black;
    overflow: scroll;
}

.header {
    height: 25px;
    background-color: #333;
    right: 0;
    left: 0;
}

.sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    width: 75px;
    margin-top: 35px;
    border: solid 1px grey;
}

.main {
    height: 100%;
    padding-left: 75px;
}

.main-container {
    width: 65%;
    height: 100%;
}

.main-content {
    height: 100%;
    overflow-y: scroll;
    border: solid 1px red;
}

.main-header {
    height: 20px;
    border: 1px solid black;
}

.detail-container {
    float: right;
    width: 35%;
    height: 100%;
    border: solid 1px grey;
}

.top-info {
    padding: 75px 0;
}

items-container {
    height: 100%;
    overflow-y: scroll;
    border: solid 1px red;
}

.item {
    padding: 100px 0;
} 

.blue { background-color: blue; }
.orange { background-color: orange; }
.grey { background-color: grey; }
.purple { background-color: purple; }

.content {
    width: 65%;
    height: 100%;
}
<div class="container">
    <div class="header"></div>
    <div class="sidebar"></div>
    <div class="main">
        <div class="detail-container">
            <div class="top-info"></div>
            <div class="items-container">
                <div class="item blue"></div>
                <div class="item orange"></div>
                <div class="item blue"></div>
                <div class="item orange"></div>
            </div>
        </div>
        <div class="main-container">
            <div class="main-header"></div>
            <div class="main-content">
                <div class="item grey"></div>
                <div class="item purple"></div>
                <div class="item grey"></div>
                <div class="item purple"></div>
                <div class="item grey"></div>
                <div class="item purple"></div>
                <div class="item grey"></div>
                <div class="item purple"></div>
            </div>
        </div>
    </div>
</div>

Answer №2

With a touch of JavaScript magic, I managed to crack this code. It's designed to automatically adjust to the varying sizes of your content blocks as long as the underlying structure remains constant.

Best of luck!

$(function(){
//setting up variables based on jQuery objects
$itemsContainer = $('.items-container');
$mainContent = $('.main-content');

$container = $('.container');
$header = $('.header');
$mainHeader = $('.main-header');    

//calculating heights
var containerH = $container.height();    
var headerH = $header.height();    
var mainHeaderH = $mainHeader.height();

//assigning new height to main-content class
$mainContent.css("height", (containerH - headerH - mainHeaderH) + "px");

//similar operation for items-container
//setting up variables based on jQuery objects
$topInfo = $('.top-info');

//calculating heights
var topInforH = $topInfo.outerHeight(); //using outerHeight due to empty content in top-info

//assigning new height to items-container class
$itemsContainer.css("height", (containerH - headerH - topInforH) + "px"); });

By the way, I've updated your jsfiddle with my solution so feel free to give it a whirl.

Answer №3

Setting the height to 100% will make the elements fill the entire space, even if other sibling elements are present. This can lead to issues with headers pushing them down. To resolve this, consider using fixed heights for all elements or allocating different percentages of height to each.

.content-section { width: 600px; }
.container-items {width: 400px; }

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

The combination of Asp.net and Bootstrap offers a powerful

I am facing an issue with using Bootstrap in my ASP.NET project. The page displays correctly on a desktop, but when I resize the page to mobile phone size, the navigation panel does not stay in dropdown position. Here is my code: <%@ Page Language="C ...

Troubleshooting an Angular.js "Hello World" application that is malfunctioning

I've been trying to get a simple Hello World app working by following different tutorials, but it doesn't seem to be functioning correctly. I've double-checked my code and everything looks right to me. Could someone please assist me in troub ...

Angular2 Components with Unique Styling

I am working on an Angular2 app that includes several components, some of which I want to reuse multiple times on a single page. Instead of having three separate components, I am looking to refactor and combine their functionalities into one. The basic st ...

Getting the text from a Selenium element can become tricky when dealing with product discounts that alter the element

(Programming) I am working on selecting random products from a website, some with discounts and some without. For instance: How do I retrieve product 748 (without discount)? or How do I retrieve product 419 (with discount)? When the product ha ...

interactive symbols in a reorganizable tree structure

I have been developing a customizable tree list for our users to arrange their website content. It allows them to add and rearrange pages by dragging and dropping. Each list item includes the page name and three icons (lock, visible, and edit). The challe ...

Having trouble accessing the href attribute after clicking on an <a> tag with JavaScript

My issue lies in retrieving the href attribute of <a> tags when there is another element nested inside them: Here's the code snippet: const $elems = document.querySelectorAll('.content-container a') var elems = Array.from($elems) e ...

Eliminate the preset padding on the left and right sides of the container-fluid in Bootstrap 5

How can I remove the default padding-left and padding-right in a container-fluid using Bootstrap 5? I don't want to use "!important" in my CSS file. I have already tried disabling the default padding with Chrome dev tools but it didn't work. Any ...

Works well with Bootstrap but not compatible with other frameworks

Looking for assistance with a code within Bootstrap (HTML and CSS). I have been trying to create a dropdown menu (burger menu) following the Bootstrap Documentation, but I am unable to expand the burger menu (Dropdown). I have tested it on both Firefox an ...

Implementing CSS keyframes when a specified PHP condition is satisfied

I am looking to implement an opening animation on my website that should only play when a user visits the site for the first time. I want to avoid displaying the animation every time the page is reloaded, so it should only run if a cookie indicating the us ...

How can I make a Bootstrap 5 container adjust to the height of the screen?

I am currently working with Bootstrap 5 and facing an issue while displaying a calendar on the screen. The height of the container appears to be around 25% longer than the screen height. I have tried setting the height to "100%" and "80%" in the CSS, but i ...

Endless Loading in Node.js on Google App Engine

I have deployed a standard nodejs app (free tier) using cloud shell, but when I try to access https://[ID].du.r.appspot.com/ , it keeps loading indefinitely. app.js: const express = require('express'); const path = require('path'); co ...

Exploring Problems with Implementing the Jquery .click() Function on a Class

My goal is to create a simple JQuery code that triggers a pop-up message saying hello when any element of the specified class is clicked. Here's what I've tried: $(document).ready(function(){ $(".thumb_radio").click(function(){ aler ...

Displaying a list within a circle that elegantly animates, and then, after two full rotations, magically morphs

Can icons be displayed in a circle and after 1,2 rotations, revert back to the list view? https://i.sstatic.net/p4Jxm.png If so, when it forms after 1,2 rotation, it should resemble a line. https://i.sstatic.net/uJW24.png In summary, looking for a CSS3 ...

What is the best way to showcase attributes in HTML using nodejs and expressjs?

I am working on a Node.js and Express application with HTML. In one of my JavaScript files, I use response.render to display an HTML page, passing variables like this: response.render('agent.html', {name: name, phone: phone}); Now, I want to kn ...

Complete a checkbox entry form and showcase it within a "division" on the current page

Hello everyone, I need some help. I have a form that I want to send to a specific div on the same page. This is what I am aiming for. I have a floating div named "basket" in the top right corner of my page where I want the form data to be displayed after s ...

Tips for automatically adjusting a vertical side bar to fit between the browser's header and bottom

I'm having trouble with aligning my sidebar vertically between the header and the bottom of the browser window. Currently, the bottom items are extending beyond the browser's bottom edge. How can I adjust this to ensure proper alignment? Here is ...

What is the method for determining the width of a Mat-Table once it has been displayed?

When utilizing Angular Material Mat-Table in conjunction with Angular 8, I am passing the dataSource dynamically. The number of rows and columns varies each time. Is there a method to calculate the width of the table once it is rendered on the screen? &l ...

What is the best way to update the src of an input using an onclick event?

When I click the input, my background changes color as expected. However, the src of the input only changes on the second click. How can I make it change the source on the first click? Also, how can I change the src back to the original with a second cli ...

Tips for honing in on a particular card within a list of cards using React

I am currently working with React 17.0.2 and Material UI, and I have a specific requirement to focus on a particular card from a list of cards by clicking on it. (Please refer to the attached picture for clarification). I hope this explanation helps you un ...

Increase the font size of a div using CSS to make it appear larger

Utilizing a WYSIWYG-editor, I am creating content that I want to display with double font-size, without directly altering the HTML code. Here is an example of the HTML structure: <div id="contents"> <p style="text-align:center"> <spa ...