A growing flexbox container that expands to a specific height before allowing for scrolling

In the case of a fixed height container with two vertical divs, I am aiming for the first div to be as tall as its content, up to 80% of the parent div's height. After that point, the content within the first div should scroll. The second div will then expand to fill the remaining space in the parent container, but always keeping a minimum height.

I have experimented with different approaches to achieve this layout, but so far it seems like JavaScript is necessary to accomplish it.

To showcase my issue, I have created a sample on codepen for others to view and potentially modify. While I understand that using JavaScript would solve the problem, I am curious if there might be a way to achieve the desired layout without relying on JavaScript.

<body layout="row" ng-app="myApp" ng-cloak>

  <div flex layout="column" class="boxWithHeight" layout-padding>
    <section flex="grow" style="overflow-y:auto"><div>Place your lengthy content here</div></section>
    <section style="min-height:100px">flex</section>
  </div>

  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.js"></script>
  <script src="https://ajax.googleapis.com/ajax/libs/angular_material/1.1.8/angular-material.min.js"></script>
  <script>angular.module('myApp', ['ngMaterial'])</script>

</body>

Answer №1

Here is the solution you were looking for.

Demo showcasing overflow

.wrap {
  height: 90vh;
  width: 90%;
  margin: 5vh auto;
  background: pink;
  display: flex;
  flex-direction: column;
}

.content {
  background: lightblue;
  max-height: 80%;
  overflow-y: auto;
}

.spacer {
  height: 200px; /* for demonstration purposes */
}

footer {
  flex: 1 0 auto;
  min-height: 50px;
  background: rebeccapurple;
}
<div class="wrap">
  <div class="content">
    <p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Maiores, pariatur cumque? Accusantium eius hic laboriosam, odio amet repellendus quo perferendis unde iure quasi, eaque similique eos architecto illo voluptatibus voluptate doloribus atque
      in deleniti placeat corrupti saepe. Animi, quisquam officia?</p>
    <div class="spacer"></div>
  </div>
  <footer></footer>
</div>

Demo without overflow

.wrap {
  height: 90vh;
  width: 90%;
  margin: 5vh auto;
  background: pink;
  display: flex;
  flex-direction: column;
}

.content {
  background: lightblue;
  max-height: 80%;
  overflow-y: auto;
}

.spacer {}

footer {
  flex: 1 0 auto;
  min-height: 50px;
  background: rebeccapurple;
}
<div class="wrap">
  <div class="content">
    <p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Maiores, pariatur cumque? Accusantium eius hic laboriosam, odio amet repellendus quo perferendis unde iure quasi, eaque similique eos architecto illo voluptatibus voluptate doloribus atque
      in deleniti placeat corrupti saepe. Animi, quisquam officia?</p>
    <div class="spacer"></div>
  </div>
  <footer></footer>
</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

Determining the pixel padding of an element that was initially set with a percentage value

I am working with a div element that has left padding assigned as a percentage, like so: padding-left: 1%; However, I need to obtain the value of this padding in pixels for some calculations after the window has been resized. When using JavaScript to chec ...

Incorporate an XNA game directly into a website

Is it possible to launch an XNA game directly from a web page without the need for any installations? Something along the lines of Java, Silverlight, or similar to WPF Browser Applications (XBAP). Situation: Visit a webpage, Prompted to install the g ...

Merging ng-if conditions

I would like to find a way for my two ng-if conditions to work together instead of separately. I want to display only the last one if both are true. Currently, this is how my code looks: <div> <img ng-src="{{img(myColor)}}" ng-if="myColor" ...

position the input and span elements side by side

Need help aligning an input and a span element next to each other. The span is currently positioned below the input, but I want it to be on the right side of the input. I am trying to create a search bar using this input and span tag, so they need to be al ...

A step-by-step guide on showcasing freshly submitted input data through Ajax

I'm having trouble with this issue! Once I submit the new input, it doesn't show up in the div. Below is my JavaScript code: $('#addVariable').validate({ rules: { variable: {required:true}} , submitHandler: functio ...

- bullet point: tabulated

I need to create an unordered list with URLs included and indented, while keeping all lines justified to the left. * line one text text ted more text text text * line two text ted more text text text * line three text ted more text text text ...

Issues with PHP not retrieving selected radio button values

Currently, I am using a PHP webpage to generate a list of all files with a .264 extension in a specific folder. Once the file is selected, it is then sent to a command for video playback on a display connected to the computer. I have encountered some diff ...

Printing the contents of a datatable in HTML can be achieved in VB.NET by including headers and setting paper orientation, fit to page, and grand total for print preview and direct print

I'm attempting to print the contents of a datatable in HTML for print preview and direct printing, including headers, setting paper size, orientation, and fitting to page in VB.NET. While it may be easy to accomplish this using an rdlc report, I am u ...

How can I send the input from a textbox to an email?

I'm looking to create a basic sign-up form where individuals can enter their email and submit it. The goal is to have this information sent via email to the site owner. I initially thought the code below would do the trick, but it doesn't seem t ...

Problem with Bootstrap Dropdown positioning on mobile devices

I have encountered a puzzling issue with our web application. To demonstrate the problem, I have simplified the page to its bare minimum. You can access it here: Everything seems to be working fine on desktop browsers. However, when I test the page on a m ...

Combining two HTML tables using jQuery/JavaScript

My table is displayed below: <table id="first" class="merge"> <tr> <td>Mick Jagger</td> <td>30</td> <td>50</td> <td>10</td> </t ...

A guide on dynamically accessing an image from the src directory using props in a Vite + React application

export default function Card(props) { return ( <card> <img className={cardCss.card__img} src={`../assets/imgs/card/${props.img}`} alt="" /> <div className={cardCss.card__stats}> ...

Menu within a menu, accessed by hovering

<nav class="navbar navbar-expand-lg navbar-dark bg-dark"> <a href="index.html" class="navbar-brand display-4">NintendoWorlds</a> <button class="navbar-toggler" dat ...

How can you spot the conclusion of different lines that refuse to remain in place?

Currently, I am facing a jquery issue that has left me stumped. The website I am working on is structured as follows: <div class="Header"></div> <div class="main"><?php include('content.html'); ?></div> <div clas ...

Manipulating the DOM in AngularJS Directives without relying on jQuery's help

Let's dive right in. Imagine this as my specific instruction: appDirectives.directive('myDirective', function () { return{ restrict: 'A', templateUrl: 'directives/template.html', link: functio ...

Utilize PHP's foreach loop to showcase information within multiple HTML div containers

I am presented with the following data and would like to showcase it in separate containers using HTML. Name Price Difference Signal CA.PA 15.85 3.5609257364073 MACD AZN.ST 896 3.4881049471963 MACD AMGN 258.57 1.6391533819031 SMA 50/ ...

I am currently engaged in a Portfolio project, where my objective is to ensure that all images are optimized for responsiveness

While Bootstrap ensures that relative images are responsive, absolute images may not be. This can cause alignment issues when the browser window is resized on mobile devices. .title-img { position: relative; width: 100%; height: 100%; } .skill-b ...

React and SASS - issue with checkbox component not being properly aligned with its label

I'm brand new to React and I'm currently in the process of converting a pure HTML page into a React component. How can I adjust the SASS stylesheet to match the original HTML layout? Here is my current React setup (the checkbox displays on the r ...

Flexbox margins (exceeding 100% total width)

Currently collaborating with @c4rlosls and we are facing 2 issues: https://i.sstatic.net/44WcI.jpg If the parent container with class container-fluid has a px-0, it extends beyond 100% width. Additionally, the elements with classes .cont2 a and .cont3 a do ...

Navigation bar text fails to display

Just starting out and trying to create a basic navigation bar, but I can't seem to get the links to show up. All that displays are the logo image and the hamburger icon. How can I make the links visible on the nav bar? Appreciate any help! <!DOCTYP ...