The height of scrollbars in the HTML section does not extend to full coverage

On my HTML webpage, I am facing an issue with the "left-section" scrollbar. It does not cover the entire height of the section. The scrollbar only appears when the window is resized small enough to reach "Link 18". Even then, the scrollbar does not scroll beyond "Link 18"; it shows only half of it.

The problem disappears when I remove the code within the <header> tags. Once removed, the scrollbar covers the full height of the column.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Two Columns with Independent Scrollbars</title>
    <style>
        /* Styles for the container */
        .container {
            display: flex;
            height: 100vh;
        }

        /* Styles for the left section */
        .left-section {
            width: 30%;
            padding: 20px;
            background-color: #f0f0f0;
            overflow-y: auto; /* Add a vertical scrollbar to the left section */
        }

        /* Styles for the right section */
        .right-section {
            width: 100%;
            padding: 20px;
            background-color: #e0e0e0;
            overflow-y: auto;
        }

        /* Style for links */
        .left-section a {
            display: block;
            margin-bottom: 10px;
            text-decoration: none;
            color: blue;
        }

        /* Hide the main page scrollbar */
        body {
            overflow: hidden;
        }
    </style>
</head>


    
<body>
   <header>
        <h1>Welcome to My Web Page Welcome to My Web Page Welcome to My Web Page Welcome to My Web Page </h1>
        <p>This is the banner section of the page.</p>
    </header>
    
    
    <!-- Banner Section -->

    <!-- Container for both sections -->
    <div class="container">
        <!-- Left Section with Independent Scrollbar -->
        <div class="left-section">
            <h3>Links</h3>
            <a href="#">Link 1</a>
            <a href="#">Link 2</a>
            <a href="#">Link 3</a>
            <a href="#">Link 4</a>
            <a href="#">Link 5</a>
            <a href="#">Link 6</a>
            <a href="#">Link 7</a>
            <a href="#">Link 8</a>
            <a href="#">Link 9</a>
            <a href="#">Link 10</a>
            <a href="#">Link 11</a>
            <a href="#">Link 12</a>
            <a href="#">Link 13</a>
            <a href="#">Link 14</a>
            <a href="#">Link 15</a>
            <a href="#">Link 16</a>
            <a href="#">Link 17</a>
            <a href="#">Link 18</a>
            <a href="#">Link 19</a>
            <a href="#">Link 20</a>
        </div>
        
        <!-- Right Section with Independent Scrollbar -->
        <div class="right-section">
            <!-- Content for the right section goes here -->
        </div>
    </div>
</body>
</html>

Answer №1

  • To ensure both the left and right sections are scrollable, set html, body to 100dvh (dynamic viewport height)
  • body should have display: flex; with direction set to column (optional to add overflow: hidden)
  • Opt for using padding over margin for better tap area for your anchors
  • Utilize flex property shorthand to expand an element within available space
  • .container also requires an overflow property other than visible

/* QuickReset */ * { margin: 0; box-sizing: border-box; }

html, body {
  height: 100dvh;
}

body {
  overflow: hidden; /* not necessarily needed */
  display: flex;
  flex-direction: column;
}

.container {
  flex: 1;
  display: flex;
  overflow: hidden;
}

.left-section {
  flex: 0 0 30%;
  padding: 1rem;
  overflow: auto; 
  height: 100%;

  & a {
    display: block;
    padding: 0.5rem 0;
    text-decoration: none;
    color: blue;
  }

}
.right-section {
  flex: 1;
  padding: 1rem;
  background-color: #e0e0e0;
  overflow: auto;
  height: 100%;
}
<header>
  <h1>Welcome</h1>
  <p>This is the banner section of the page.</p>
</header>
<div class="container">
  <div class="left-section">
    <h3>Links</h3>
    <a href="#">Link 1</a>
    <a href="#">Link 2</a>
    <a href="#">Link 3</a>
    <a href="#">Link 4</a>
    <a href="#">Link 5</a>
    <a href="#">Link 6</a>
    <a href="#">Link 7</a>
    <a href="#">Link 8</a>
    <a href="#">Link 9</a>
    <a href="#">Link 10</a>
    <a href="#">Link 11</a>
    <a href="#">Link 12</a>
    <a href="#"><a>Link 13</a>
    <a href="#">Link 14</a>
    <a href="#">Link 15</a>
    <a href="#">Link 16</a>
    <a href="#">Link 17</a>
    <a href="#">Link 18</a>
    <a href="#">Link 19</a>
    <a href="#">Link 20</a>
  </div>
  <div class="right-section">
    <p style="height: 200vh;">Some test paragraph really tall...</p>
  </div>
</div>

Answer №2

After some research, I discovered the solution. The key was to deduct the height of the from the lower divs.

height: calc(100vh - 80px);

Answer №3

To ensure proper display, specify the height for .left-section as either 76vh or in pixels using 'px'.

.left-section {
    width: 30%;
    padding: 20px;
    background-color: #f0f0f0;
    overflow-y: auto;
    height: 76vh;
}

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

Explore a variety of themes for the antd design token

Is there a way to access the text color of both the default and dark themes using design tokens? I am looking for a method to seamlessly switch between the two color schemes based on specific conditions, without having to change the entire theme. For ins ...

Creating a repeating sequence in HTML: A step-by-step guide

I have an HTML file containing a portfolio. Each portfolio item is structured like this: <div class="item"> <div class="portfolio-item"> <a href="img/portfolio-item-1.jpg" data-lightbox="ima ...

A guide on rotating loaders and inserting custom text within loaders using CSS

Seeking assistance to modify my code for creating a unique loader design. The inner loader needs to remain static with only top and bottom segments, while the middle loader rotates anti-clockwise and the outer loader rotates clockwise. Additionally, the ...

Using jQuery to iterate over a multi-dimensional array and showing the child elements for each parent array

I am facing an issue with a multidimensional array that contains objects and other arrays. While it is simple to loop through the parent array and display its contents in HTML, I encounter a problem when there are multiple layers of arrays nested within ea ...

"Can you explain the method by which reveal.js adjusts the size of

I have been exploring the resizing behavior of elements in reveal.js and trying to understand how they dynamically adjust. If you resize the page height, you can observe that the elements shrink up to a certain extent along with the page. However, when in ...

From transitioning from a radio button's checked indicator to a complete button

I'm in the process of customizing my WordPress plugin and seem to be struggling with styling the radio buttons. For reference, you can find the code snippet here: https://jsfiddle.net/cd3wagvh/ The goal is to conceal the radio buttons and modify the ...

What is the most effective method for displaying two external web pages next to each other?

Looking for a solution to display an English Wikipedia article on the left side of the page alongside its Spanish version on the right side. Wondering if it's possible using HTML, JavaScript, AJAX, etc. I am aware that I could use iframes, but I woul ...

Is there a way to eliminate the additional and varying pseudo-padding on text inputs in both Webkit and Gecko browsers?

The issue I'm facing is specific to input[type="text"] elements in Webkit. No matter what adjustments I make, it seems like there is an additional padding: 1px 0 0 1px (top and left only) applied to the element. A similar anomaly occurs in Gecko as w ...

Showing a JavaScript variable on an HTML page

I have a challenge where I am attempting to showcase a variable using the code provided below: HTML: <div id="MyEdit">Money</div> JS: var price1 = 0; var current_value=document.getElementById("MyEdit").innerHTML; if (current_value == "msc" ...

What could be causing the calendar icon to not display in the table cell?

I've been working with the Bootstrap date picker inside a table, and I'm having trouble getting the date picker icon to display using the fas fa-calendar-alt css class. <td> <input type="text" id="expirydate{{$index}} ...

css issues with setting background colors

I am in the process of updating the header on a website, and I want the entire header to have a light gray background. My initial approach was to set the background-color of the main header div to gray (E7E7E7), but for some reason, there is now a white sp ...

SyntaxError: Unexpected '<' symbol found in JavaScript file while attempting to import it into an HTML document

This issue is really frustrating me In my public directory, there is an index.html file Previously, I had a newRelic script embedded within the HTML in script tags which was functioning properly Recently, I moved the script to a separate JavaScript file ...

How to display a three.js scene in the center of a container

I'm having trouble getting my three.js scene to display above some cards and right below my navigation bar. Currently, the scene is rendering under the cards and is not centered. Despite looking at other forum posts for help, I can't seem to figu ...

Python: Change text within HTML content rather than the HTML tags

Looking for help with converting HTML code? <pre class="script">template("main/GlobalShared");</pre> <pre class="script"> var link = '/Draft/Tracker_1.1'; if (wiki.pageexists(link)) { &lt;div class="version"&gt; web ...

Encountering a TypeError while attempting to utilize Django and Pandas for displaying data in an HTML format

import pandas as pd from django.shortcuts import render # Define the home view function def home(): # Read data from a CSV file and select only the 'name' column data = pd.read_csv("pandadjangoproject/nmdata.csv", nrows=11) only_city ...

Tips for displaying Ajax response in a modal popup

I have a link that, when clicked, sends an AJAX request and successfully receives a response in the form of an HTML file, which I then append to a div. However, I want to display this div as a modal popup and I have attempted the following: In the HTML fi ...

What is the best way to use Google Material-Design-Icons in my project once I have installed it

Once I've installed the material-design-icons package using npm, how can I incorporate them into my React application? The instructions provided here do not mention the npm method. ...

Experience the convenience of Visual Studio Code's auto-completion feature for HTML tags even when working within an

My HTML file has a babel script embedded within it. <!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <title>React tutorial</title> <script src="https://unpkg.com/react@16/umd/react.development.js" ...

Including HTML attributes within a PHP script

Currently, I am working on developing a message to be displayed to the user after they have submitted the contact form using PHP. However, I am facing an issue with styling the message as intended, particularly with elements like bold text and line breaks ...

Angular: Disabling a button based on an empty datepicker selection

Can anyone help me figure out how to disable a button when the datepicker value is empty? I've tried using ngIf to check if the datepicker is empty and then disable the button, but it's not working. My goal is to make the button unclickable if th ...