Scrollable divs in a Bootstrap layout

If you take a look at this fiddle I created, you can see what I've attempted. My goal is to have a webpage without scroll bars but with the col-left and col-right divs getting a scrollbar when they overflow.

Could someone provide some insight on what I might be missing? Alternatively, if there's a more efficient solution using Bootstrap, please feel free to share it with me.

I'll include the HTML code here as well for future reference when the fiddle expires.

<!DOCTYPE html>
<html lang="en>
  <head>
    <meta charset="utf-8">
    <:title>title</title>
  </head>

  <body>

<div class="container-fluid" id="my-container">
  <div class="row" id="my-full-row">


  <div class="" id="my-menu-col">
    M
  </div>

  <div class="col">
    <div class="row" id="my-title-row">
      Title row
    </div>
    <div class="row" id="my-row">
      <div class="col-sm-2" id="my-col-left">
        col left<br/>col left<br/>... (content continues)
      </div>
      <div class="col-sm-10" id="my-col-right">
        col right<br/>col right<br/>... (content continues)
      </div>
    </div>
  </div>
  </div>
</div>

And here is the CSS:

html, body {
  height: 100%;
  margin: 0;
}
.row {

    margin: 0px;
}
.col {

    padding: 0px;
}

#my-container {
  height: 100%;
  padding: 0px;
}

#my-full-row {
    height: 100%;
}

#my-menu-col {
  height: 100%;
  width: 50px; 
  background-color: purple;
}

#my-title-row {
  background-color: red;
  height: 50px;
}

#my-row {
  background-color: blue;
  height: 100%;
}

#my-col-left {
  background-color: green;
  overflow-y: scroll;
}

#my-col-right {
  background-color: yellow;
  overflow-y: scroll;
}


#u { background-color: #337ab7; }

Answer №1

Your CSS could benefit from some tidying up to avoid unnecessary repetition. To achieve the desired effect of preventing scrolling in a high viewport, you should consider removing the height: 100%; property from the #my-row element.

Additionally, I recommend including the following code snippet:

#my-col-left, #my-col-right {
  height: 100%;
}

Answer №2

i have adjusted the height to 100vh for #my-col-left and #my-col-right, and added overflow:hidden to the body in this code snippet. Feel free to use this CSS in your file as it should work seamlessly.

html, body {
  height: 100%;
  margin: 0;
  overflow:hidden; /*added*/
}
.row {
    margin: 0px;
}
.col {
    padding: 0px;
}

#my-container {
  height: 100%;
  padding: 0px;
}

#my-full-row {
    height: 100%;
}

#my-menu-col {
  height: 100%;
  width: 50px; 
  background-color: purple;
}

#my-title-row {
  background-color: red;
  height: 50px;
}

#my-row {
  background-color: blue;
  height: 100%;
}

#my-col-left {
  background-color: green;
  overflow-y: scroll;
  height:100vh;/*added*/
}

#my-col-right {
  background-color: yellow;
  overflow-y: scroll;
  height:100vh;/*added*/
}


#u { background-color: #337ab7; }
<div class="container-fluid" id="my-container">
  <div class="row" id="my-full-row">


  <div class="" id="my-menu-col">
    M
  </div>

  <div class="col">
    <div class="row" id="my-title-row">
      Title row
    </div>
    <div class="row" id="my-row">
      <div class="col-sm-2" id="my-col-left">
        col left<br/>col left<br/>col left...
      </div>
      <div class="col-sm-10" id="my-col-right">
        col right<br/>col right<br/>col right...
      </div>
    </div>
  </div>
  </div>
</div>

Answer №3

By using the CSS property overflow-y: auto;, you can display a scrollbar only when content overflows the container.

Additionally, it is necessary to set a height limit for your div. The following rules were modified accordingly:

#my-col-left {
  background-color: green;
  overflow-y: auto;
  height: 100vh;
}

#my-col-right {
  background-color: yellow;
  overflow-y: auto;
  height: 100vh;
}

To see the outcome, you can visit this link: https://jsfiddle.net/o0czt2ua/

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

Animation scaling on the iPhone seems to abruptly jump away once it finishes

Encountering an issue with animations that is causing unexpected behavior on physical iPhone devices but not in the simulators. The problem arises when the background zooms in and then the div suddenly jumps to the left after the animation completes, as sh ...

Incorrect positioning of dropdown menu when using Bootstrap 4 and translate3d() function

Having multiple bootstrap 4.4.1 dropdown menus, each within a column which is functioning correctly except for the position calculation. Example of HTML col: <div class="container"> <div class="row"> <div class="col"> <div ...

Are there any libraries available to simplify HTML development in C#, .NET, or ASP.NET?

I have a vivid memory of stumbling upon a project where an individual utilized json-like strings to generate high-quality HTML in a certain programming language. Is there a similar tool available for use with C# or .NET? radio-box{ AName, [First|Second| ...

Issue with triggering (keyup.enter) in Angular 8 for readonly HTML input elements

My goal is to execute a function when the user presses Enter. By setting this input as readonly, my intention is to prevent the user from changing the value once it has been entered. The value will be populated from a popup triggered by the click attribut ...

Tips for adjusting the width of items within the Box element in Material UI React

I am utilizing React Material UI along with the Box component to style my form. In this scenario, I have 4 items in each row except for the last row where I need to display only 3 items with the last item filling the entire row by merging two elements toge ...

Alignment in HTML / CSS / ReactJS: Leveraging the Text-align attribute

My attempt to align the text to the right within my div element has been unsuccessful. Despite using text-align: right and width: 100%, the issue persists. It seems that the problem lies within the left-side and right-side attributes, but I am unable to pi ...

What is the best way to highlight the option with a value of 0 by giving it a red background using either CSS, jQuery, or both, regardless of whether it is

I have tried various CSS and jQuery combinations to address the issue of displaying the option with a value of 0 in red only when it is not selected. .red { background: red; } select option[value=0] { background: red; } <select id="ups"> < ...

Is there a method to generate an endless carousel effect?

Hello, I am trying to create an infinite carousel effect for my images. Currently, I have a method that involves restarting the image carousel when it reaches the end by using the code snippet progress = (progress <= 0) ? 100 : 0;. However, I don't ...

Vuetify Card Overflow: Handling Multiline Text with Ellipsis

I have been experimenting with Vuetify cards and encountered an issue with their height. In the image below, you can see that the cards' height varies until it reaches a specified max-height of 225px. I want to implement a text-overflow: ellipsis feat ...

Creating Space in CSS between Two Widgets

Is there a way to align the managers tab under the checkers and stockers areas on this page? The current setup has the manager button overlapping with both of them. If anyone has any suggestions on how to address this issue, I'm all ears. Thank you! ...

Firefox experiencing issues with width scaling

I'm having an issue where the main image is not resizing when I adjust the window size, specifically in Firefox. Here is the URL in question: How can I solve this problem? I attempted using width: 100% in .banner_right, but it only made things worse ...

How to Trigger a Validation Error on an HTML Template Using Django

I'm encountering an issue with displaying a validation error message on my HTML template when the form is not submitted correctly. In my forms.py file, there is a function (clean_email) that successfully identifies if the email entered does not contai ...

Submit a form to the same page without reloading and toggle the visibility of a div after submission

Is there a way to submit a form without refreshing the page and hiding the current div while showing a hidden one? I attempted to use the following code, but it ends up submitting the form and reloading the page. <form method="post" name="searchfrm" a ...

What is the best way to connect Bootstrap icons to hyperlinks in Ruby?

Hello, I'm currently attempting to connect a Bootstrap icon link with its corresponding text to a specific link. I have tried enclosing the svg tag in single quotes, but it just returns a string. Here is the current code: <li class="n ...

Combining divs with identical values in Angular

I am working on creating my very own custom Calendar. Take a look at the full example of my component here I need help figuring out how to combine week divs that share the same value {{day.weekNumber}} so that there is only one div for each shared value, ...

Using ngb-carousel to display embedded YouTube iframe videos

Can anyone help me figure out how to embed an Iframe into a ngb-carousel? The carousel is displaying correctly, but the iframe tab is not showing up as expected. <ngb-carousel *ngIf="project.images"> <ng-template class="item" n ...

Arranging elements on the top of an image

I am struggling to replicate a design and align some items properly without resorting to absolute positioning. The design I want to achieve looks like this https://i.sstatic.net/HaOXT.jpg https://i.sstatic.net/EovkI.jpg The grey area represents a section ...

Efficiently styling table Spans with styled components in React

Can anyone help me with a frustrating CSS problem I'm facing? I am trying to render these tags as spans, but they are not separating properly as shown in the image below. They appear stuck together and I can't figure out why. I am using styled co ...

What is the best way to divide data using [/ -]?

I am trying to split a string that shows a date. The date is shown in the format dd/mm/yyyy or dd-mm-yyyy. This is my code (the current string is formatted as mm/dd/yyyy): <input type="data" id="dat"> ..... var dataString=$('#dat').val(); ...

Adjust the background to scroll to the bottom of the image first and then change it to be fixed

Here is the code I have written: body{ margin:0; padding:0; line-height: 1.5em; background-image: url(http://fehlbelichtet.stefanwensing.de/wp-content/uploads/sites/6/2016/04/alte-strasse-endlos.jpg); background-repeat:no-repeat; background-attachment: ...