Achieving fixed full height divs with scrollbars in Bootstrap can be accomplished by following these steps

I am currently working on a Bootstrap page layout with three columns, each set to 100% height and equipped with scrollbars, while keeping the body free of any scrollbars. The desired layout should look like this: https://i.sstatic.net/sA5Bb.jpg

Here is my code so far:

<main role="main" class="container">
    <div class="row">
        <div class="col-md-3 ">
            Navigation Area <br />
        </div>
        <div class="col-md-6">
            Content Area <br />
        </div>
        <div class="col-md-3">
            Profile Area <br />
        </div>
    </div>
</main>

As of now, I have not applied any additional CSS styles. Can you guide me on how to successfully achieve this desired layout?

Answer №1

Get rid of the body's scrollbar

To remove the scrollbar, apply overflow: hidden

body {
    overflow-y: hidden;
}

Add a scrollbar to each column part

To add a scrollbar, use overflow: scroll

main div[class*="col-"] {
    overflow-y: scroll;
}

Make it reach full height

To achieve that, you should use height: 100vh and subtract your navbar's height from it. The default bootstrap navbar height is 116px (including padding).

main {
    height: calc(100vh - 116px);
}

Here's a Live Snippet for You

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">

<style>
    body {
        overflow-y: hidden;
    }
    main div[class*="col-"] {
        overflow-y: scroll;
        height: 100vh;
    }
</style>

<main role="main" class="container-fluid">
    <div class="row">
        <div class="col-md-3 ">
            [Insert Lorem Ipsum text here]
        </div>
        <div class="col-md-6">
            [Insert Lorem Ipsum text here]
        </div>
        <div class="col-md-3">
            [Insert Lorem Ipsum text here]
        </div>
    </div>
</main>

Answer №2

Adjust the positioning of elements by making parent-main relative and child-settings absolute. Add overflow: auto; height: 100% to enable overflow for child elements. To remove the navbar height from the page, utilize

height: calc(100vh - "nav-height")

.main {
  position: relative;
  width: 100%;
  height: 100vh;
}

.settings {
  overflow: auto;
  height: 100%;
  width: 100%
}
<!DOCTYPE html>
<html lang="en">

<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
</head>

<body>
  <div class="container-fluid">
    <div class="row">
      <div class="col-sm-6">
        <div class="main">
          <div class="container settings" style="position: absolute;">
            <div class="box no-box-small-mobile">
              <div class="column">
                <h1>test</h1>  
                              ... (remaining content omitted for brevity)              
                                       ...                
            </div>
          </div>
        </div>
      </div>
      <div class="col-sm-6">
        <div class="main">
          <div class="container settings" style="position: absolute;">
            <div class="item">
              <div class="label">A thing</div>
              <div class="value">1.45</div>
             ...              
                             ...
                                   ...
                        

        </div>
      </div>
    </div>
  </div>
</body>

</html>

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

Customize the appearance of polygons in OpenLayers 2 by adjusting the fill color and opacity

I am aiming to use different fill colors and opacity values for various shapes (such as Triangle, Circle, Square, Hexagon, etc.). Although I can draw the shapes, set different titles, and stroke colors with the code below, I'm struggling to define th ...

What is the best way to ensure elements expand to the full width when the body exceeds 100% width?

While this layout functions properly on the majority of modern browsers thanks to bootstrap's responsiveness, issues arise when testing on older browsers. https://i.sstatic.net/e7qDT.png The problem seems to stem from the wide element extending beyo ...

Chosen Buttons for Emailing

I have recently created a multistep form and have implemented functionality to receive the form contents via PHP email. However, I am facing a challenge where, when I navigate through the form and encounter multiple buttons to choose from, the email I rece ...

Content towering over the footer

Can anyone help me figure out how to create a footer that appears behind the content when you scroll towards the end of a website? I've tried looking for tutorials online, but haven't found exactly what I'm looking for. Most of what I'v ...

The size of divs adjust based on the size of the browser window

Within a container div, I have multiple nested divs arranged side by side. The container is 1100px wide and centered in the browser window. In the example image below, three inside divs are illustrated, but there could be more (divD, divE, etc). https://i ...

Function activation in Element requires a double click to initiate

I've encountered an issue with a web element I'm working on where the click function only triggers after the first click, rendering the initial click ineffective. Here's the code snippet in question: HTML: <div> <a href="#0" cla ...

Adding DIV elements within a Bootstrap Carousel

I've successfully placed containers inside my Bootstrap Carousel slides that overlay the image with text and a link. It looks great initially, but I'm facing an issue where after switching to the next slide, I can't return to the one with th ...

Creating a single div to influence the height of surrounding divs

Here is a fiddle you can check out: http://jsfiddle.net/thiswolf/RGe24/3/ to see the image div and the orange and middle divs stretch to match its height without padding the orange box towards the bottom. Here is the HTML code: <section class="les_hea ...

I'm currently in the process of incorporating horizontal scrolling into various sections of an image gallery. The images will stack vertically only when the window width

I am currently developing an image gallery with multiple sections that contain various images. My goal is to arrange each section of images in a single row, allowing horizontal scrolling similar to Netflix's layout. However, I'm facing challenges ...

FLASK Template Rendering

I am encountering an issue with refreshing the page, specifically when I click the button that is meant to filter data using an ajax script. The problem arises when the IF condition does not work and prevents rendering of the template. Below is a snippet o ...

Challenges with Bootstrap input groups

Despite trying various solutions, nothing seems to be working for me. I attempted using width:200px, but the issue persists. Since my form was quite outdated, I decided to switch to a bootstrap version. However, while others are able to resolve the issue w ...

Using the mouse scroll to activate the $anchorScroll effect in Angular instead of a click

I have been searching for a solution to my problem without any luck so far. Hopefully, someone here can provide guidance and help me find a solution. My goal is to replicate the behavior shown in the second example on the following page: https://docs.angu ...

"Adapting Bootstrap dropdown menu to display in the top left corner

While working on a navbar featuring three nav-items with a dropdown-menu class each, I encountered an issue. The first nav-item's dropdown-menu displays correctly, but for the other two, the dropdown-menu seems to shift to the top left. You can view ...

Ratios for Sizing Bootstrap Columns

The Bootstrap grid system consists of 12 columns in total. I am looking to utilize all 12 columns on the page. However, my goal is to have the first 6 columns on the left side be half the width (50%) of the columns on the right side. This means that the ...

How can the position of Bootgrid's pagination element be fixed in relation to its parent container, no matter how many table rows are present?

I've been struggling to keep the pagination section of a JQuery Bootgrid table I'm building in the right position. No matter what I do, it always seems to be aligned with the last row of the table. I attempted setting the container div as relativ ...

Is there a better method to determine the width when utilizing the jQuery UI resizable feature for improved efficiency?

I'm currently working on a website that features a resizable sidebar. I want the icons and text within the sidebar to shrink proportionally when the user resizes it. Right now, I have implemented an if statement to check if the sidebar's width fa ...

Fixed table layout prevents table cells from expanding inside a 100% width table row with absolute positioning, while also ensuring that the elements do not collapse

I'm struggling to understand this, as I am not very well-versed in CSS. I would consider myself more of a beginner than an expert. The reason why I am using relative/absolute is because I am working with dynamically paginated tables from large datase ...

Tips for rearranging a span following an image?

Looking for a solution to rearrange a span element after an image within automatically generated HTML. Sample HTML: <span>closed</span> <img alt="Click to reset" src="xxx" class=""> Currently, the span appears before the img in the cod ...

Click on the submenu to expand it, then simply select the desired option to navigate

I have created a toggle menu that displays a list of child elements when clicked, and hides them if clicked again. However, when a child element is clicked, I want it to navigate to the corresponding page. I am having trouble getting this functionality to ...

Stencil - React Integration Does Not Support Global CSS Styling

As per the guidance provided in the Stencil docshere, I have established some global CSS variables within src/global/variables.css. This file is currently the sole CSS resource in this particular directory. Upon attempting to incorporate my components int ...