Issue with overflow-auto not displaying scroll bar

In my layout, I have a grid parent with two columns. The left child has a height equal to the parent (100vh), while the right child is 1000px tall, which exceeds the parent's height.

Here is the HTML structure:

<body>
    <div class="leftcol"></div>
    <div class="rightcol"></div>
</body>

And here is the corresponding CSS code:

body{
    background-color: white;
    display: grid;
    grid-template-columns: 2fr 3fr;
    margin: 0;
    overflow: hidden;
}

.leftcol {
    background-color: grey;
    height: 100vh;
    width: 100%;
}

.rightcol {
    background-color: black;
    height: 1000px;
    width: 100%;
    overflow: auto;
}

I aim to make only the right child scrollable, as its height surpasses that of the parent, ensuring the left child remains fixed in place. However, despite setting overflow: auto on the right child, it does not function as expected. Can anyone point out what mistake I might have made? Thank you.

Answer №1

For the right column, it is recommended to add an inner child element. The height of the right column should match that of its parent which is set to 100vh. If the inner element is specified to be 1000px in height, this may cause the parent element .rightcol to overflow if the height exceeds the maximum allowable height.

*{
  box-sizing: border-box;
}

body{
    background-color: white;
    display: grid;
    grid-template-columns: 2fr 3fr;
    margin: 0;
    overflow: hidden;
}

.leftcol {
    background-color: grey;
    height: 100vh;
    width: 100%;
}

.rightcol {
    background-color: black;
    height:100vh;
    width: 100%;
    overflow: auto;
    padding:20px;
}

.inner-col{
  height: 1000px;
  background: green;
}
<body>
    <div class="leftcol"></div>
    <div class="rightcol">
      <div class="inner-col"></div>
    </div>
</body>

Answer №2

give it a go

<body>
    <div class="leftcol">
        <p class="top">top</p>
        <p class="bottom">bottom</p>
    </div>
    <div class="rightcol">
        <p class="top">top</p>
        <p class="bottom">bottom</p>
    </div>
</body>

<style type="text/css">
    body{
        background-color: white;
        display: grid;
        grid-template-columns: 2fr 3fr;
        margin: 0;
    }

    .leftcol{
        background-color: grey;
        height: 100vh;
        width: 50%;
        position: fixed;
        left: 0;
        top: 0;
    }

    .rightcol{
        background-color: black;
        height: 1000px;
        width: 50%;
        position: absolute;
        right: 0;
        top: 0;
    }
    .leftcol p,
    .rightcol p {
        text-align: center;
        color: #fff;
    }
    .rightcol p.top {
        top: 0;
    }
    .rightcol p.bottom {
        bottom: 0;
        padding-top: 900px;
    }
    .leftcol p.bottom {
        padding-top: 80vh;
    }
</style>

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

Using an HTML element to pass a variable into a replace function

I am looking to highlight a 'SearchString' by replacing it with <span style="background-color: yellow">SearchString</span> within a targetString. The SearchString varies, so I am wondering how I can make this happen. This is what I ...

What is the best way to get both the id and name of a selected item in Angular?

Within my select field, data is dynamically populated based on names. My objective is to not only capture the selected name but also its corresponding ID. Here's a snippet of my HTML template: <select class="custom-select d-block w-100" id="test" ...

What is the best way to eliminate the excess space below the footer on a vuejs page?

I am developing a footer using vuejs along with buefy. In my implementation of App.vue below, I am encountering a white margin under the footer. // App.vue <template> <div id="app"> <main-header /> <router-view/ ...

`Make adjustments to the visual representation of crispy forms`

When using crispy forms, the labels for CheckboxSelectMultiple() fields are populated from the default string representation of objects defined in a list. To change this behavior, I am seeking assistance. Is it possible to create a custom string represent ...

Retrieve the border color using Selenium WebDriver

Hey everyone, I'm currently trying to retrieve the border color of an extjs 4.2 form control text field using the getCssValue method. However, I'm having trouble getting the value as it's coming back blank. Below is a sample of my code that ...

Learn how to retrieve and transfer data from a MySQL database table to a hidden input field in an HTML form using PHP

I have a scenario where a user fills out the first form, submits it, and the details are saved in a database table. After that, I need to set a value from the data sent to the database into a hidden input field in the second form upon clicking a button. To ...

Using jQuery to append text after multiple element values

I currently have price span tags displayed on my website: <div> <span class="priceTitle">10.00</span> </div> <div> <span class="priceTitle">15.00</span> </div> <div> <span class="priceTitle">20.0 ...

Trouble with Google Web Fonts appearing incorrectly on Chrome for Windows 7

Currently facing an issue with a website I am developing using Wordpress: In Chrome, running on Windows 7, the body text on the homepage is supposed to be displayed as a Google Font. However, for some reason, the last line of the text is appearing in the d ...

Is there a way to extract a variable value from an external webpage in order to manipulate

Although I am not well-versed in PHP, I believe it may be the most suitable solution for achieving my goal. I want to extract the value of a variable from an external page in order to process it for generating graphs and statistics on my own webpage. The s ...

The multiple-choice selection tool is not displaying any choices

I am having an issue with my ng-repeat code in conjunction with the jquery multiple-select plugin. Despite using this plugin for a multiple select functionality, the options generated by ng-repeat are not visible. Below is the code snippet in question: & ...

A guide on utilizing radio buttons to delete specific rows within a table with the help of AngularJS

My current issue involves using radio buttons to delete rows in a table. The problem I'm encountering is that multiple rows are being deleted at once instead of just one. You can view an image of my table here. As we all know, with radio buttons, onl ...

If the td element contains text, add a comma (,) and wrap the text in HTML tags. If there

Currently diving into some jQuery code and have come across a few uncertainties. Here is what I've managed to put together so far: var html = ''; data.entities.forEach(function (value, index, array) { html += index !== data.entities.len ...

Learn the method of showcasing a JavaScript variable value within an HTML href tag

Currently, I am in the process of rewriting my URL and category name to be passed into the URL. For this purpose, I am creating a URL friendly string using the following JavaScript function: function getUrlFriendlyString(str) { // convert spaces to &ap ...

What is the best way to display the loan detail and credit detail tables beneath the application detail section that is currently blank?

I have a total of four tables on my page. The size of one table is almost identical to the other three smaller tables. I am looking to place the loan details and credit details table below the application detail, in a way that utilizes the empty space avai ...

"Quotes are essential in Javastript syntax for specifying string values

I need to implement a JavaScript syntax to generate unique URLs for each image. The Robohash website provides random robot images based on different URL endings. I tried the code below, but it seems like ${props.id} is being interpreted as part of the UR ...

The radio button allows for the selection of multiple items, rather than just one at a time

https://i.sstatic.net/9MEzS.png I have implemented a radio input as shown below <input type="radio" id={el.name} className="form-check-input" name={el.name} data-count={el.name} value={el.id} onChange={this.select_role.bind(this)} style={{margin: "4px ...

Using " " to split a name into two lines is not being recognized

My issue involves the display of tab names in two lines within multiple tabs. You can view the demonstration here. I attempted to use the \n character while setting the tab name but it was not recognized. Any suggestions on how to achieve this? Here ...

Using the <video /> tag on a Next.JS page generated on the server side leads to hydration issues

My Next.js app's index page is rendered on the server side by default. During development, I encountered an error that stated: Unhandled Runtime Error Error: Hydration failed because the initial UI does not match what was rendered on the server. Wa ...

Display the source code of an HTML element when clicked

Is there a way to show the source code of an element on a webpage in a text box when that specific element is clicked? I am wondering if it is feasible to retrieve the source code of an element upon clicking (utilizing the onClick property), and subseque ...

What is the best way to use jQuery to position a <div> at the bottom of another <div>?

Is there a way to achieve something similar to this concept? https://i.sstatic.net/xhewF.png The dimensions displayed are just for visualization purposes, but feel free to utilize them. I am interested in moving the smaller red <div> box and attac ...