When three divs with overflow scroll exceed the maximum height of 100%, they will not fit on the page

body,html{
  max-height:100vh;
}
#content{
  max-height:100%;
}


#div1,#div2,#div3{
  background:#fff;
  overflow-y:scroll;
  max-height: 30%;
}

I'm struggling to get this to function properly.
For instance, "title2" should have an overflow scroll but instead it continues overflowing its parent. It doesn't fit within the page's max-height of 100%.

Check out the example here

Answer №1

Regrettably, the use of overflow: scroll is not viable when the height is specified as a percentage, which is your current setup. An alternative approach would be to utilize vh units instead, offering similar functionality to percentages for sizing.

If you're unfamiliar with what vh entails, check out this informative article:

For illustration purposes, here's a code snippet:

body,
html {
  max-height: 100vh;
}
#content {
  max-height: 100%;
}
#div1,
#div2,
#div3 {
  background: #fff;
  overflow-y: scroll;
  max-height: 30vh;
}
<div id="content">
  <h2>
title1
</h2>
  <div id="div1">
    <div>row</div>
    <div>row</div>
    ...
    <div>row</div>
  </div>
  ...
  <h2>
title2
</h2>
  <div id="div2">
    <div>row</div>
    <div>row</div>
    ...
    <div>row</div>
  </div>
  ...  
  <h2>
...
    <div>row</div>
)</div>

Answer №2

Let's see if I understood this correctly. I created a JSFiddle example

Simply swap out max-height:30% with max-height:33vh

Answer №3

give this a try and hopefully it will work for you. Here is a fiddle link: https://jsfiddle.net/cbjkc4dg/4/

Make sure to enclose each block with a div tag like shown below:

<div class="block">
   <h2>title1</h2>
   <div id="div1">
     <div>row</div>
     <div>row</div>
     <div>row</div>
     <div>row</div>
   </div>
 </div>

As for the styling, you can set the height of the main parent container to 100vh to make its parent element flexible as well. See example below:

body,
html {
 overflow: hidden;
}

#content {
 height: 100vh;
}

.block {
 height: calc(100vh / 3);
 overflow: hidden;
}

#div1,
#div2,
#div3 {
 background: #fff;
 overflow-y: scroll;
  height: calc(100% - 37px);
}

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

Troubleshooting issues with adding rows to an HTML table

I want to include two buttons at the top of my page: Save and Cancel. These buttons should only appear after clicking the Submit button on the Customer Information panel. However, when trying this, the Customer Information panel is pushed down while I al ...

Fuzzy Background to Enhance Your Bootstrap 5 Offcanvas Navigation Menu

Currently utilizing Bootstrap v5.2, I am endeavoring to replicate the image displayed in the link below: Blurry Sidebar Backdrop As per the MDN Documentation, backdrop-filter is intended for blurring the background of an element. .offcanvas-backdrop { ...

While working on coding, the background of the Bootstrap 4 navbar seemed to have disappeared

I am a newcomer to Bootstrap, and while trying to make a navbar more responsive for all screen sizes and add some effects, I somehow lost the background color of my navbar. I attempted to explicitly change the color by altering the navbar-light class, but ...

Is it possible to highlight the original 'anchor' or position of an element that has been moved using the float property?

Can the XXX be displayed using a CSS trick without the need for an extra HTML element or container? I attempted to use pseudo-elements and translate, but it was unsuccessful. p { background-color: grey; max-width: 200px;} small { float: right; margin-r ...

Customizing the field_error_proc in Rails is causing issues with the HTML layout

Within a rails application, I have customized the field_error_proc to enable inline error displays as shown below: https://i.sstatic.net/DjmdN.png The code snippet for achieving this functionality is outlined here: ActionView::Base.field_error_proc = pr ...

Instructions on implementing a floating label on a select2 dropdown menu

I am currently utilizing the select2 plugin for my select dropdowns on a webpage. I have multiple select dropdown boxes and I need to implement a floating label specifically for the selected dropdown. Despite my efforts and searches, I have not been able ...

Working with Ext JS: Dynamically adjusting panel size when the browser window is resized

I am facing an issue with a side panel in Ext.js. Everything is working fine until I resize the browser, at which point some components of the panel get cut off. https://i.sstatic.net/eaEGI.png Is there a way to make the panel resize automatically when t ...

Creating Bootstrap carousel indicators within a navbar can enhance the user experience and navigation of

I have a well-functioning carousel that slides perfectly between each image, but I am looking to highlight the active item when sliding and clicking on the navbar menu links. Can anyone point me in the right direction with this? HTML CODE: <nav class= ...

Execute a function within the ajax success callback

I have crafted a code snippet that scans through all images within a specified div and assigns classes based on their sizes. Currently, this functionality is set to run when the document loads, and it works flawlessly upon initial page load. However, I a ...

What is the best way to ensure that all elements are perfectly centered in an

After conducting a thorough check, it has been confirmed that this post is not a duplicate. The circumstances surrounding my question are completely unique compared to other similar inquiries. I am working with an ASP.NET page that has an unspecified widt ...

Delayed loading of CSS within app-root component in Angular

Currently, I am working on integrating an animation when the app starts within the contents of <app-root>...</app-root>. To achieve this, I have made the following changes: <app-root> <style> h1 { font-family: &ap ...

Unable to stack DIVs in a vertical arrangement

I'm having trouble replicating the 2:1 layout shown in the image below. The issue I'm facing is with aligning the two photos on the right vertically so they match perfectly with the photo on the left. I attempted using flex but the vertical distr ...

Place a full-width block within a grid design

I am currently working on a page layout inspired by Google Images. It features a grid of images with a large full-width section underneath the selected image. I am interested to see if it is achievable using CSS properties like display: grid. https://i.ss ...

What is the best way to center these icons vertically in my navigation menu using CSS?

My website has a navigation menu with third-party icon libraries (Material/FontAwesome) in use. I am facing an issue where the icons are not aligning vertically with the anchor text. Adjusting the font size of the icon to match the text results in it appe ...

Bootstrap 3's responsive embed feature is not functioning as expected

Hey everyone, I'm in the process of building a website with Bootstrap 3 and everything has been going smoothly so far. However, I've run into an issue when trying to embed a YouTube video using the responsive embed class provided by Bootstrap. De ...

The parent is relatively positioned and its child is absolutely positioned and floated to the left

I'm currently working on a design where I have a group of parent containers with the float left property applied. Inside each parent container, there is a child div with position absolute defined within them. Here's an example: <div class="wr ...

CSS Opacity Issue

Why is the article transparent? Despite my efforts to search online for similar instances, I am surprised at not finding anything and feeling quite puzzled about what steps to take next. body { background-color: #000000; opacity: 0.8; background-i ...

Troubleshooting IE7's overflow problem

In my website, I have a ul element with overflow-y set to auto for displaying a nice scroll bar with all the li elements. However, in IE7, this setting is ignored and the list overflows outside the container. To see the issue directly, you can visit http: ...

Showing headings in the table vertically

I have a header1 and header2 with corresponding data1 and data2 that I want to display differently. h h e e a a d d e e r r 1 2 data1 data2 To enhance the presentation, I wish to add borders around the head ...

Can you provide instructions on how to adjust the width of a form using a JavaScript script within a CSS file?

I am currently working on creating a form where individuals can input their email addresses to receive some information. My goal is to design one HTML file that will work seamlessly on both desktop and mobile views by adjusting the form width based on th ...