What could be causing my divs to not properly handle overflow with the overflow-y scroll property?

I'm struggling with making my sidebar and content area responsive in terms of height. I want them to adjust to fill the screen appropriately, rather than having a fixed height. The issue arises when I have varying content heights, such as when a page banner is displayed, causing the layout to respond inconsistently.

I've experimented with setting overflow-y: scroll on both the tab-content container and tab-panes individually, as well as adjusting heights and max heights. However, no matter what I try, if a tab-pane contains too many items, it overflows and causes the entire page to scroll instead of just adding a scrollbar to the tab pane.

I've provided an example on JS Fiddle to illustrate the problem. In the overview section with minimal inputs, there is no scrollbar. But in a large section like section 4, a page scrollbar appears due to uncontained overflow. This results in the sidebar also getting scrolled, making the layout messy.

My goal is to confine the content within the maximum available screen space, without relying on specific pixel or view-height values to stay responsive. Any solution should ensure that the content remains visible on the screen even when the alert div is uncommented.

Check out the JS Fiddle example

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

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

<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="73111c1c07000701120333465d435d41">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5a3835352e292e283b2a1a6f746a7468">[email protected]</a>/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>

<body>
  <style>
    body {
    display: flex;
    height: 100vh;
    flex-direction: column;
  }
  .sidebar {
    max-width: 18rem;
  }

  .tab-content {
    overflow-y: scroll !important;
    max-height: 99%;
    height: 99%;
  }

  .tab-pane {
    overflow-y: scroll !important;
    /* max-height: 99%; */
    /* height: 99%; */
  }
  </style>

  <div class="container-fluid flex-grow-1 row">  
    [Content of the page goes here]
  </div>
  
</body>

Answer №1

This issue arises from using a percentage for setting the height of the div.

Here are the recommended adjustments:

  1. Add overflow-y:hidden; to the body CSS.

  2. Modify the .tab-content CSS by changing height and max-height values to 99vh instead of 99%.

See the working example below:

 /* CSS code to solve the issue */
body {
  display: flex;
  height: 100vh;
  flex-direction: column;
  overflow-y: hidden;
}

.sidebar {
  max-width: 18rem;
}

.tab-content {
  overflow-y: scroll !important;
  max-height: 99vh;
  height: 99vh;
}

.tab-pane {
  overflow-y: scroll !important;
}
<!-- CDNs for Bootstrap CSS and JS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>

<body>
  <!-- Content structure with Bootstrap classes -->
  <div class="container-fluid flex-grow-1 row">
    <nav class="col-auto sidebar px-2 bg-dark">
      <ul class="nav flex-column nav-pills mx-3" role="tablist" aria-orientation="vertical">
        <li class="nav-item">
          <a class="nav-link  active" id="sidebar_overview" data-bs-toggle="pill" data-bs-target="#section_overview" type="button" role="tab" aria-controls="section_overview" aria-selected="true">
                Overview
            </a>
        </li>
        <!-- Additional navigation items omitted for brevity -->
      </ul>
    </nav>

    <form action="" class="col tab-content">
      <fieldset class="tab-pane fade show col ms-5 mt-4 active" id="section_overview" role="tabpanel">
        <!-- Section content goes here -->
      </fieldset>
      <!-- Additional tab sections omitted for brevity -->    

    </form>
  </div>

</body>

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

Unable to create a flawless circle using Canvas

No matter how hard I try, drawing a perfect circle seems impossible for me. Every time I attempt it, all I manage to create is an ellipse. Check out this code snippet I put together as an example: function canvasClicked(number) { var c = "canvas" + nu ...

Add your logo and personalized graphic to the top header section of your website using the Divi Wordpress theme

Can a logo and custom graphic be placed in the "top-header" section (i.e. to the left of the phone number) within the well-known ElegentThemes Divi template? I experimented with absolute positioning and adjusting the container/body to relative. The code c ...

Tips for halting the live graph plotting based on a specific condition with canvas js

I have a piece of code that generates a live graph based on probabilities. I am looking for a way to stop the plotting process as soon as a specific condition is met. <script> window.onload = function () { var dps = []; // dataPoints var c ...

Adjust the size of a menu by modifying its width

Hey everyone, I recently joined this website and I'm still learning how to code. My current project involves creating an off-canvas menu, but I've come across a few challenges. Firstly, does anyone know how to adjust the width of the menu when it ...

Creating a JSON object for an HTML form with AngularJS can be easily accomplished by following these steps

Currently, I am diving into the world of AngularJS. I'm familiar with creating a JSON object for my HTML form using jQuery, but now I want to do it with AngularJS. Can someone please guide me on how to accomplish this task in AngularJS? Your help is g ...

The default setting for my bootstrap modal is displayed, not hidden

Is there a way to make my bootstrap model hidden by default and only visible when I click on a link? I'm new to web development and would appreciate any help. tst.html <!DOCTYPE html> <html lang="english"> <head> < ...

Retrieve and substitute attributes using preg_replace

I'm looking to add tabs to all the properties listed here, but I am having trouble isolating the properties as $1 is not working in this case. A small tweak would solve this issue... Thank you! $css = <<<EOF body { padding: 0px; ...

When employing a CSS combination of `position: fixed;` and `display: flex;`, the upper portion of the inner element is excised and out of reach

I'm currently working on a fullscreen modal and facing an issue with centering the content vertically when it is smaller than the screen. Additionally, I need the content to start at the top and allow scrolling when its height exceeds the container&ap ...

"Upon loading the page, I encounter JavaScript errors related to Angular's ngOnInit function. However, despite these errors,

I have a page in angular where I am loading data in the ngOnInit function. The data loads correctly and is displayed on the page, everything seems to be working fine. However, I am encountering numerous javascript errors in the console stating cannot read ...

How can I make my navbar visible once a specific section has been reached?

Is there a way to conditionally display my navbar in react only when a specific section is reached? Currently, I am monitoring scroll position but this method becomes unreliable on larger screens due to varying scroll positions. I need the navbar to beco ...

Creating an arrow dialog box in Material UI: A step-by-step guide

I have successfully created an arrow box (div) using custom CSS and HTML. However, I am facing difficulty in implementing the same design in Material UI with React JS. The code below demonstrates how to achieve this using custom CSS. My question is: How ...

The Zurb Foundation has a multitude of redundant CSS entries

I have been utilizing Zurb Foundation for a while now, with a bower + compass setup as outlined in the documentation here. Recently, I encountered an issue where a specific page was loading slowly. Upon investigating, I discovered that there were numerous ...

Is there a way for me to attach a link to a picture displayed in a lightbox that directs to an external ".html" file?

I have a platform where users can view images in a gallery and when they click on an image, it opens up in a lightbox. I am trying to add a feature where the opened image can be clicked again to redirect the user to an external page. I attempted to nest t ...

Error message: The method z.fn.dropdown is not defined

I am looking to implement a basic select option using bootstrap-select. My goal is to use bootstrap-select for creating the select picker. Upon checking the console, I come across this error message: https://i.sstatic.net/XUJYy.png Below is the HTML cod ...

Positioning a sticky footer in a dual-column design

This updated post is a revised version of the one found at this link. I aim to provide a clearer explanation of my issue compared to the previous post. The problem revolves around the placement of the footer in two different scenarios. Scenario 1: https: ...

Steps for updating the homepage to display a personalized welcome message to the user after logging in and redirecting using node.js and

Upon arriving at the homepage, simply click on the sign-in button. Once redirected back to the home page, you will notice a personalized greeting saying 'Welcome [user]'. Wondering how to achieve this? It's as simple as changing the text fro ...

What is the best way to keep a <div> class anchored to the bottom of an HTML page?

I am looking to incorporate a footer into my website that stays fixed at the bottom of the screen. However, I have encountered an issue: Here is what I have attempted so far: .footer { position: absolute; width: 100%; background: #0084FF; ...

How to make divs occupy the entire space of a parent div?

I've been scouring the website for a solution, but nothing I've found has been helpful. I'm attempting to create a grid within a containing div where a default (and eventually user-specified) number of divs will fill up the space. I'm t ...

Tips for adjusting the color of a row when hovering

Can I modify the row color on hover in material-table using props? Similar to this example. Appreciate your help. ...

Activate a change or response when the input value in Javascript is altered

Currently, I am working on a small project using JQuery and facing an issue when trying to remove error classes from HTML elements. To handle the removal of the error classes, I am utilizing $('selector').on('input') event to target th ...