Managing overflow in CSS divs

Two divs are needed in this layout, where the first div adjusts its height based on the content and the second div takes up the remaining space. The second div should be scrollable to display all items. Here is the design template: https://i.sstatic.net/MI07Y.png

For a demonstration, refer to my example on JSFiddle. Please note that only CSS is used, no JavaScript.

<div class="tbl">
  <div class="header">
    <p>1</p>
    <p>2</p>
  </div>
  <div class="body">
    <div class="in-body">
        <p>3</p>
        <p>4</p>
        <p>5</p>
        <p>6</p>
        <p>7</p>
        <p>8</p>
        <p>9</p>
        <p>10</p>
    </div>
  </div>
</div>

Answer №1

Check out the new design! I've adjusted the second div to take up at least 35% of the window height. If you want to change the minimum height of the second div, just modify the 65vh on the wrapper. (Remember that 100vh represents the viewport height, and the remaining space is allocated to the second div).

body {
  margin: 0;
}
.wrapper {
  width: 35%;
  max-height: 65vh;
  position: relative;
}
.first,
.second {
  width: 100%;
  color: white;
  padding: 15px;
  box-sizing: border-box;
}
.first {
  background-color: green;
}
.second {
  background-color: blue;
  position: absolute;
  height: calc(100vh - 100%);
  top: 100%;
  overflow-y: auto;
}
<div class="wrapper">
  <div class="first>
    kitsch flannel direct trade listicle ramps truffaut.
  </div>
  <div class="second">
    Brunch fingerstache bespoke squid neutra. Cred hella meh, slow-carb kale chips fashion axe vinyl keytar banjo butcher ethical affogato taxidermy. Bicycle rights venmo lomo truffaut. Art party kickstarter vice, truffaut yr 90's farm-to-table. Banh mi try-hard
    distillery, next level mumblecore jean shorts sustainable drinking vinegar squid banjo 3 wolf moon. Slow-carb waistcoat fashion axe, try-hard kinfolk flexitarian hella pitchfork semiotics truffaut blue bottle stumptown. Asymmetrical skateboard distillery
    chambray.
  </div>
</div>

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

Change the value of a div element from a decimal number to an integer

Suppose we have <div id="mydiv>>111</div> in an HTML document and the intention is to extract this number using GetElementbyID(myid).value and convert it to an integer Attempts have been made with ParseInt, ParseInt(x, 10), Number(x).... ...

Extracting information from a webpage is becoming time-consuming when utilizing Selenium and BeautifulSoup

Is there a way to optimize web scraping requests for efficiency when dealing with multiple pages on a website? The current method I am using is taking too long, especially with a large number of links to scrape. The code snippet provided below showcases t ...

Customizing CSS Styles Based on Browser Specifications

Attempting to utilize conditional stylesheets for targeting different versions of IE. Currently have the following setup: <!--[if IE 7]> <link href="_includes/css/ie7.css" rel="stylesheet> <![endif]--> <!--[if gte IE 7]> <link ...

I am experiencing difficulty with my background image loading as it requires a specific pixel value for height

Having trouble loading an image as a responsive background image in my CSS. Here's the code I'm using: .cover{ height: auto; width: 100%; background-image: url(../img/cover.jpg); background-repeat:no-repeat; background-size:c ...

Continuously spinning loading icon appears when submission button is triggered

We are currently experiencing some issues with our mobile forms. Our users utilize a mobile form to submit contact requests, but the problem arises when they hit 'submit' - the loading icon continues to spin even after the form has been successf ...

CSS not being applied to certain HTML elements due to an error in implementation

Utilizing Bootstrap's vue form-group has been instrumental in my creation of input fields. I am currently attempting to apply specific CSS styling to the 'legend' element within the following code: <fieldset id="__BVID__59" class="form-g ...

Limiting the types of files a user can access through a web browser

Hey there! I have a unique question that sets it apart from others, as it involves restricting file types for users with a browser popup. My goal is to prevent users from selecting certain file types before they choose a file. I've come across some s ...

html/css: managing content overflow in web pages

While studying CSS, I created a sample page and encountered an issue where two of my divs were overflowing the content of the body, with the footer appearing above those divs. body { background-color: white; } #div1 { margin: 50px; text-align: jus ...

CSS/Jade/HTML: struggling to get boxes to align properly on the same line

I'm currently working with a Jade template that looks like this: extends layout block content h2 Characters and Portraits div(id="portraitsBox") - var portraits = ["Clown-Fox", "Dragon-Bear", "Fish-Bear", "Deer-Wolf", "Salamander-Ant", "Sid ...

Tips for adjusting jCountdown timer to be auto responsive while utilizing CSS sprite resources

The jCountdown plugin creates stunning effects that can be viewed at: After inspecting the resources, it appears that the plugin uses css sprite animation to achieve its effects. I am curious about how challenging it would be to make it responsive and avo ...

Utilize Bootstrap 3 Datepicker version 4 to easily set the date using Moment.js or Date objects

I'm currently utilizing the Within my project, I have a datetime picker labeled as dtpFrom <div class='input-group date ' id='dtpFrom'> <input type='text' class="form-control" /> <span c ...

Aligning rotated text in a bootstrap 4 table header

In my Bootstrap 4 project, I'm having difficulties with positioning rotated text within a table header. My goal is to align all the rotated text at the bottom of the cell and centered horizontally. Despite trying different transform-origins, it seems ...

Is there a way for me to extend an absolute div to the full width of its grandparent when it is within an absolute parent div?

Here is a structured example of my HTML and CSS: <div class="grandparent"> <div class="row">...</div> <div class="absolute-parent"> <div class="absolute-child">...</div> ...

Error: Trying to access the parent node of an undefined property

After incorporating this script into my webpage for the newsletter sign-up process, I aimed to reveal customized content post user subscription. <script> function insertAfter(referenceNode, newNode) { referenceNode.parentNode.insertBefore(newNode ...

One PHP File Solution for Customizing Tab Colors

Apologies for the vague title, I am having trouble explaining my issue. I have successfully created panel tabs using ol, li, and css. Everything works perfectly except for one problem that arose in the program – this tab li class="current". The purpose ...

Guidelines for managing a catch function

I have recently set up a database in Cloud Firestore and am looking to populate it with information using input fields. However, I've encountered an issue where if the input fields are left empty, the information still gets stored and the catch functi ...

Unable to retrieve information from the table using watir-webdriver

As a beginner in Ruby and watir-webdriver, I am facing an issue with pulling data from a website. I am unable to access a specific cell in an HTML table as there are no distinguishing id, name, or class attributes. My suspicion is that the table is generat ...

Automatically close the multiselect dropdown when the user interacts outside of it (varied scenario)

For those interested, check out this jsfiddle link: http://jsfiddle.net/jaredwilli/vUSPu/ This specific code snippet focuses on creating a multi-select dropdown feature. When a user chooses options from the dropdown and then clicks outside of the menu are ...

What steps can I take to ensure that the full tingle modal, which includes an image, is visible when the

Upon loading the page, I noticed that if the browser width is greater than 540px, the modal displaying an image gets cut off (see figure below). What steps should I take to ensure that the vertical scroll bar appears immediately? https://i.sstatic.net/cJv ...

Creating a scrolling sidebar in Bootstrap 4

Today I learned about CSS Bootstrap 4 and created my template with a sidebar. However, when there are many menus, I want the sidebar to show a scrollbar. I am looking for help on how to make a scrollbar appear on my sidebar template. Below are my HTML and ...