Steps for implementing overflow scroll on a div with an unspecified height

The layout I'm working with looks like this:

.page {
  width: 360px;
height: 704px;
border: 1px solid red;
}

header {
  height: 10%;
  width: 100%;
  display: flex;
  align-items: center;
justify-content: center;
  background-color: lightblue;
}

main {
  height: 90%;
  background-color: beige;
  width: 100%;
  
  display: flex;
  flex-flow: column;
}

.container-dynamic {
  width: 100%;
  height: 400px;
  border: 1px dashed grey;
  
  display: flex;
  align-items: center;
  justify-content: center;
  
  flex: 0 0 auto;
}

p {
  text-aling: center;
}

.container-fill {
  width: 80%;
  
  border: 1px dashed black;
  
  height: auto;
  
  flex: 1 1 auto;
  
  
}

.c {
  width: 100%;
  background-color: lightgreen;
  padding: 10px;
  
  max-height: 100%;
  
  overflow: scroll;
  
  flex: 1 1 auto;
}

.b {
  width: 80%;
  height: 200vh;
  background-color: lightblue;
}
<div class="page">
  <header>
    HALLO
  </header>
  <main>
    <div class="container-dynamic">
      <p>This container has dynamic height</p>
    </div>
    <div class="container-fill">
      <p>This container fills up the left space</p>
      <div class="c">
        <div class="b">
        </div>
      </div>
    </div>
  </main>
</div>

Currently, the green area extends beyond the boundaries of the .page element. My goal is to have the green area fill the available space on the page. I've managed to achieve this by applying flex: 1 1 auto to .c and using display: flex, flex-flow: column on the main element. However, I also want the green area to be scrollable when its content (in this case, the light blue rectangle .b) exceeds its size. Unfortunately, setting overflow: scroll on the green element hasn't worked as expected based on the code provided. Any assistance in accomplishing my desired outcome would be greatly appreciated.


While one approach could involve calculating the remaining height using JavaScript, I'm interested in learning if there's a CSS-only method to achieve the same result.

Answer №1

.page {
  width: 360px;
height: 704px;
border: 1px solid red;
}

header {
  height: 10%;
  width: 100%;
  display: flex;
  align-items: center;
justify-content: center;
  background-color: lightblue;
}

main {
  height: 90%;
  background-color: beige;
  width: 100%;
  
  display: flex;
  flex-flow: column;
}

.container-dynamic {
  width: 100%;
  height: 400px;
  border: 1px dashed grey;
  
  display: flex;
  align-items: center;
  justify-content: center;
  
  flex: 0 0 auto;
}

p {
  text-aling: center;
}

.container-fill {
  width: 80%;
  
  border: 1px dashed black;
  
  height: 100%;
  
  flex: 1 1 auto;
  
  
}

.c {
  width: 100%;
  background-color: lightgreen;
  padding: 10px;
  
  max-height: 100%;
  
  overflow: scroll;
  
  flex: 1 1 auto;
  box-sizing: border-box;
}

.b {
  width: 80%;
  height: 200vh;
  background-color: lightblue;
}

.scroll-elem-container {
  flex-grow: 1;
  overflow: hidden;
}
<div class="page">
  <header>
    HELLO
  </header>
  <main>
    <div class="container-dynamic">
      <p>This div adjusts its height dynamically</p>
    </div>
    <div class="scroll-elem-container">
      <div class="container-fill">
        <div class="c">
          <div class="b">
          </div>
        </div>
      </div>
    </div>
  </main>
</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

Struggling with aligning Bootstrap 5 navbar items to the right while keeping the brand on the left side?

I'm struggling to align the items to the right on my navbar. No matter what I try, they just won't budge from the left side next to my brand logo. Here's the code I'm working with: <nav class="navbar navbar-expand-lg navbar-dar ...

Obtain the range of values for a match from an array using Vue.js

I have an array in my Vue.js code with values 25, 100, 250, and 500. I am looking to find the key value that matches a specific range. For example, if the input is 5, then the output should be 25. However, the code I tried returns all values within the ran ...

Utilize Moment.js in AngularJS for formatting dates

I have been attempting to use moment.js in Angularjs to format a date, but it seems like I am running into some issues. Here is the link to my code snippet on jsfiddle http://jsfiddle.net/sed6x5e8/ and below you can find the HTML and JS code that I am work ...

Looking for a way to sort through data using the current time as a filter

In my possession is an object presented below: const user = { id: 3, name: "Clark Kent", mobileNumber: "1234567892", email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="385d40595548545d674d4b ...

Cover the entire page with a solid background color

Is there a way to extend the green color from top to bottom on the page? Also, how can I move the CRUD section to the left? https://i.sstatic.net/pXxhl.png I'm having trouble filling the entire page with the content. Below is my code written in Vue ...

Javascript AppendChild Problem with Internet Explorer

When it comes to this particular snippet of code, everything seems to run smoothly in Firefox and Chrome. However, Internet Explorer is causing some major headaches. var anotherDiv= document.getElementById("anotherDiv"); var destination = document.getElem ...

When using the React Material Tree Table, I expect any new row added to automatically expand by default in the table tree structure

<MaterialTable title="title" columns={columns} data={data} icons={tableIcons} parentChildData={(row, rows) => rows.filter((item) => item.id === row.productId)} /> ...

Displaying properties of a class in Typescript using a default getter: Simplified guide

Here is an interface and a class that I am working with: export interface ISample { propA: string; propB: string; } export class Sample { private props = {} as ISample; public get propA(): string { return this.props.propA; } public se ...

JS/PHP: No error message will be alerted

<script type="text/javascript"> $(function() { $("#continue").click(function () { $.ajax({ type: "POST", url: "dbc.php?check=First", data: {full_name : $('#full_name').val(), usr_email : $('#usr_ema ...

What is a way to create a colored <hr> element without increasing its height at all?

I'm facing a dilemma - I created an hr element and it's currently grey, but I want to change the color to black. The issue is that when I do this, it appears thicker and ruins the overall styling of my page. Does anyone have any ideas on how I ca ...

Checking if a module is loaded through dynamic route code splitting

One issue with code splitting is that when the module is large, the initial loading time may result in a blank screen and delay for the user. function errorLoading(err) { console.error('Dynamic page loading failed', err); } fu ...

Experiencing Limitations with Node.JS node-hbase Scan Functionality, Unable to Retrieve More than 1000

I am facing an issue while trying to retrieve records from an HBase table in Node.JS using the node-hbase module, which connects to the rest server. I am able to fetch the first batch of records successfully, but I am struggling to get the next set of re ...

Using Vue.js to loop through data objects when a button is clicked

I'm currently working on building a quiz functionality using vue.js, but I've hit a roadblock in trying to make the "Next" button cycle through my data. The goal is to have the screen display the object containing the question and answers (e.g. q ...

iterating over a large multidimensional array in JavaScript

I am facing a challenge with handling a large JSON dataset (around 20k+ entries, totaling over 2mb) that I need to display on my web pages. Currently, I fetch this data using AJAX and parse it using JSON.parse in JavaScript, resulting in a complex multidi ...

Having trouble adjusting the height of <a> elements in the navbar

My navbar has an issue where the listed items do not fill the entire height of the navbar. I have tried adjusting padding and margin, but it doesn't seem to be affecting the layout. Any suggestions would be greatly appreciated. Thank you. #navbar { ...

Troubleshooting why Swift Mailer is failing to send emails

Trying to send an email with an attachment using Swift Mailer, but the email is not being sent. As a PHP beginner, I am struggling to identify and fix the issue. Here is the code snippet: <?php require_once 'swift/lib/swift_required.php'; $ ...

Error: Variable 'err' is undefined in Node.js

Why am I getting a ReferenceError: err is not defined even though it is supposed to be defined here? const sampleObject = require('./sampleObject'); const sampleModel = (callback) => { if (true) { sampleObject.sampleRetrieval(err ...

Retrieve the value of the chosen option from a dropdown menu that adjusts dynamically within

I have a query that involves dynamically adding rows to a table for data insertion. A particular <td> element houses a dropdown menu, and I need to extract the selected value from this dropdown in order to make an AJAX call back to a PHP script that ...

How can I correct the error in accessing state data with a getter and displaying the outcome in a component?

I am relatively new to vuejs 3 and vuex 4. I'm currently attempting to create a simple getter, but when it didn't work as expected, I resorted to using console.log to check the output. The result that appeared in the console was: ComputedRefImpl ...

Divide HTML elements every two words

Can you use CSS to break up HTML content after every 2 words, ensuring it works for any word combination? Example: // Original HTML content The cat is sleeping // Desired result: The cat is sleeping ...