Can you help me properly position a scroll bar in the lower-right corner of the div?

I am in the process of designing a web page layout with three sections - left, top right, and bottom right. The left and bottom right sections should have scrollbars, and the entire page should fill the screen. I am utilizing Bootstrap 4 for this project.

While I have successfully implemented the scrollbars for the left region, I am facing an issue with the right regions - the horizontal scrollbar only appears on the bottom-right section as intended, but the vertical scrollbar appears on the entire page. It is important to note that the bottom-right section does have a vertical scrollbar, but it seems to be disabled.

#outer {
  height: 100vh;
  overflow: none;
}

#left-col {
  height: 100vh;
  overflow: scroll;
  background-color: #ff85d4;
}

#left-large {
  height: 5000px;
  width: 5000px;
}

#right-col {
  height: 100vh;
}

#right-top {
  background-color: #abff64;
}

#right-bottom {
  overflow: scroll;
  background-color: #ccddff;
}

#right-bottom-inner {
  width: 2000px;
  height: 2000px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container-fluid">
  <div class="row" id="outer">
    <div class="col-9" id="left-col">
      <div id="left-large">
        Large left
      </div>
    </div>
    <div class="col-3" id="right-col">
      <div id="right-top">
        <p>
          Top 1
        </p>
        <p>
          Top 2
        </p>
        <p>
          Top 3
        </p>
      </div>
      <div id="right-bottom">
        <div id="right-bottom-inner">
          Right bottom inner
        </div>
      </div>
    </div>
  </div>
</div>

Is there a way to enable the bottom-right region to have its own scrollbars?

Answer №1

In response to the comments, I have found an alternative method using CSS grid, which appears to be the ideal tool for a layout that is inherently "gridy" :)

I have allocated sufficient space to all the boxes, allowing for convenient scrolling and adjustment as needed.

Update: I have set the right-top box to max-content to expand based on the content length, while ensuring the right-bottom box has a minimum height of 20px.

body {
    padding: 0;
    margin: 0;
}

.wrapper {
    display: grid;
    grid-template-columns: 1.6fr 0.4fr;
    grid-template-rows: max-content minmax(20px, 1fr);
    gap: 1rem;
    height: 100vh;
    width: 100vw;
}

.wrapper-inner {
    height: 2000px;
    width: 2000px;
}

.left,
.right-top,
.right-bottom {
    overflow: auto;
    padding: 1rem;
}

.left {
    grid-row-start: 1;
    grid-row-end: 3;
    background: hotpink;
}

.right-top {
    background: lime;
}

.right-bottom {
    background: skyblue;    
}
<div class="wrapper">
  <div class="left">
    <div class="wrapper-inner">
        Large left
    </div>
  </div>
    <div class="right-top">
        <p>
            Top 1
        </p>
        <p>
            Top 2
        </p>
        <p>
            Top 3
        </p>
    </div>
    <div class="right-bottom">
        <div class="wrapper-inner">
            Right bottom inner
        </div>
    </div>
</div>

Answer №2

To ensure a scrollbar appears on a specific block element, it is necessary to establish a fixed height and incorporate either the overflow-x:scroll or overflow-y:scroll property depending on the desired scrollbar location.

For a horizontal scrollbar, implement overflow-x:scroll;, while for a vertical scrollbar, utilize overflow-y:scroll;

Answer №3

flexbox is incredible
CSS

/*Allow children to have automatic fixed height*/
#right-col {
    display: flex;
    flex-direction: column;
}

#right-top {
  height: fit-content; /*Use only necessary space*/
}

#right-bottom {
  overflow: scroll; /*View child content*/
  height:100%; /*utilize all remaining height*/
}

Answer №4

After realizing that the height needed to be clearly defined (either as a percentage or a fixed number), I couldn't come up with a CSS-only solution.

So, I decided to utilize a ResizeObserver to monitor any changes in the size of the right-col and right-top elements (the size of the right-top element tends to change in my specific case). I then calculated the height of the right-bottom element (

right-col.height - right-top.height
) and dynamically applied it as a style to the right-bottom element.

It's not the most elegant solution, but it does the job.

I also experimented with using a CSS grid instead of bootstrap, but encountered issues with scrollbars misbehaving when the height of the right bottom element wasn't explicitly defined.

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

Angular routes cause a glitch in the Bootstrap navbar, causing it to shift to the left on certain active

Apologies for the simple question, I am new to web design and couldn't find a solution even after extensive googling and searching. The issue I am facing is that when clicking on "EX5" or "EX6" in my navbar, it shifts to the left side of the screen i ...

Displaying a background image in Laravel using the storage directory

Can anyone offer some guidance on how to load a background image from storage? I have tried using the following code with normal img src, but it doesn't seem to work with background images. background-image: url({{ Storage::get("{$post->image}") } ...

The POST method in XHR encounters issues on IOS when used with the Canvas to Blob script

Observation I've noticed a specific part of the code that's not functioning correctly only on IOS devices. xhr.open('POST', 'upload.php', true); xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded"); var da ...

Ways to incorporate vertical alignment while adjusting the size of a <div> block

Seeking advice on how to vertically align <div> blocks (green blocks in my example) when changing block size. What adjustments are needed in my example for the vertical alignment (middle) of side blocks to be maintained when resizing the browser win ...

Creating a Navigation Bar in Outlook Style Using Javascript and CSS

Looking for a navigation sidebar design similar to Outlook for my web application. I have seen options available as Winform controls and through Visual WebGUI, but these are Microsoft-dependent solutions. We need a Javascript & CSS based solution that is s ...

What is the most effective method for integrating additional CSS/JS libraries into a GitHub repository?

I would like to integrate FontAwesome, Bulma, jquery, and jquery-ui into one of my Github repositories for the front-end section. Currently, I am including the JS files or CSS files from these projects in my own JS/CSS folders, but I believe there might ...

What steps should I take to make the image appear on the browser?

I am having trouble displaying an image on a webpage in the browser. Despite using the correct path to the image, only the alt tag is being shown along with an ordered list below it. Strangely, Visual Studio Code suggests files while building the path in t ...

(jquery) Show or Hide One Dropdown Element Singularly

I'm currently working on creating a mobile side navbar that features dropdowns with additional links. One issue I'm facing is trying to set it up so that when a link in the navigation is clicked, only the corresponding dropdown activates. At the ...

The origin of the image is specified within the HTML document

I recently encountered an issue while trying to include images in my HTML file. When I used a local file path like background-image: url('file:///C:/Users/faycel/Desktop/site%20guide/paris.jpg'), the image displayed correctly. However, when I tri ...

How to retrieve the image source from a block using jQuery

Currently, I am working on developing a slider for my webpage using jquery's "Cycle" plugin. However, I have encountered an issue with accessing the image sources used in the slider. To provide more context, here is a snippet of code from the 'he ...

Ensure that HTML5 form fields are validated dynamically to make them mandatory

I have a form created using Bootstrap that contains several fields. By default, the first and second fields are required. Now, if the third field is filled out, the fourth field becomes mandatory. Similarly, if the fourth field is filled out, the third fi ...

The Regex.Replace function is not functioning as expected

I am currently faced with the challenge of replacing HTML tags within a string. For example, I need to convert <strong>text</strong> to <b>text</b>, among other similar replacements (although I understand that the b tag is considere ...

Navigate between tabs with a single click

Hey there! I'm having trouble putting together a webpage that features a sidebar. I want to make it so that clicking on one of the links at the top will switch the tab and its content accordingly. However, the current code I have isn't working an ...

Is it possible to create a QR Code using Ionic 5?

Is there a way to generate QR Codes in Ionic 5? I attempted it, but keep receiving an error stating that the qrcode element is not recognized. Here is my code: qrcode.html <ion-item> <ion-input type="text" placeholder="My QR d ...

Achieving a fixed footer at the bottom with absolute positioning on a webpage

I'm facing an issue with positioning a footer on my webpage, which is made up of div sections that are absolutely positioned. The problem arises because using the bottom property fixes the footer to the bottom of the screen rather than the bottom of t ...

Spinning with animation in jQuery

Greetings! I am in the process of creating a popup box that will appear upon clicking the Login button. My aim is to produce a popup box with a rotating effect, however, my attempts have not been successful so far. You can view the code snippet on JsFidd ...

The amazing property of AngularJS - Scope

I have saved this HTML code in a file. Here is the HTML : <!-- checkbox 1 --> <input type="checkbox" name="checkbox1" id="checkbox-group1" ng-model="checkbox1" value="group1"> <input type="checkbox" name="checkbox1" id="checkbox-group2" ng ...

I'm currently facing difficulties trying to implement AJAX with JavaScript and PHP as the desired output is not being

My query is quite straightforward - why isn't the code functioning properly? I am attempting to have the text echoed in PHP displayed inside a div with the ID of "show". Interestingly, this works with a txt file but not with PHP or any other type of f ...

The issue arises when trying to use both CSS Sprite and Background Gradient simultaneously in Chrome/Safari

Lately, I've been having issues with the gradient not displaying correctly in Webkit, although it seems to be working fine in Firefox. Could someone take a look and see if there's an error in how I set it up? Please disregard the images, as it&ap ...

Setting initial opacity for CSS on page load

I'm not a pro at web design, but I'm trying to create my own website. I've divided my page into two sections - the left side for the menu bar and the right side for content. To add a 'cool' blur effect over my menu bar, I decided t ...