Ensuring that the containing element always spans the full height of the page, regardless of the varying number of dynamic child elements

I am struggling to make a container div expand dynamically in height so that it always matches the height of its content.

The overall structure is

search.html

<div class="outer-container">
  <div class="inner-container">
    <div class="body">
      <app-results></app-results>
    </div>
  </div>
</div>

results.html

<div class="card" *ngFor="let c of content; let index = index">
  <h1 class="h">{{index}}</h1>
</div> 

I have experimented with setting the .outer-container to [display: inline-flex][1];, which initially works well. However, when more cards are added dynamically to the view, the containing element remains fixed at its original position and does not adjust to accommodate the new content.

I have also tried various combinations of height: auto and height: 100% on all elements in the hierarchy, but I encounter issues where the parent's height either shrinks or appears too short when additional children extend beyond the page height.

In addition, using overflow: auto in my app results in a double scrollbar, making it unsuitable for this scenario.

How can I ensure that the container's full height remains consistent regardless of the number of elements?

More detailed StackBlitz available here. Click on the "search" link to navigate to the correct route (I included angular router to accurately reproduce the issue).

Answer №1

After reviewing your StackBlitz project, it appears that the issue you are encountering is related to the pink background not extending when the 'toggle' button is clicked. To resolve this issue, simply include overflow: auto; in your CSS code snippet below. I have tested this solution on your StackBlitz and it resolved the problem.

.outer-container {
  width: 100%;
  position: relative;
  height: 100%;
  display: inline-flex;
  flex-direction: column;
  background: pink;
  overflow: auto;
  .inner-container {
    height: inherit;
  }
}

The overflow property determines how an element should behave when its content overflows its box boundaries.

Answer №2

After making a few adjustments in your stackblitz, I observed that it now operates as per your specifications. You just need to set the .outer-container height to fit-content and specify a min-height of 100%:

.outer-container {
  width: 100%;
  position: relative;
  height: fit-content;
  min-height: 100%;
  display: inline-flex;
  flex-direction: column;
  background: pink;
  .inner-container {
    height: inherit;
  }
}

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

What is the relationship between three.js transforms and CSS3 3D-transforms?

I am developing a unique open-source tool for exploring and visualizing the complexities of human anatomy. At the center of this tool is a dynamic 'chessboard' that occupies the majority of the screen. As you drag the board, various CSS3 3D-tran ...

Developing hybrid applications without using Angular or React

As a newcomer to Hybrid App Development, I recently created a website using core coding without frameworks like Angular or React. Now, my goal is to transform this website into a Hybrid App. However, I'm facing some lingering questions that I couldn& ...

Troubleshoot: Font Rendering Issue with CSS3 @font-face in Opera 11.x

Having some trouble with Opera not displaying my HTML5 site correctly. Everything looks good in Safari, Chrome, IE9, Firefox 3.5+ and more. Wondering if anyone has encountered this before and found a solution. Here's the breakdown of my setup: In the ...

Decipher and comprehend the buttons listed in the language translation document

Looking for assistance with a pipe issue. I've created the following custom SafeHtmlPipe: import { DomSanitizer } from '@angular/platform-browser'; import { Pipe, PipeTransform, SecurityContext } from '@angular/core'; @Pipe({ nam ...

Utilizing clip-path polygons for effective styling on Firefox and iOS

I have been working on a plugin to create animated modal boxes by utilizing the clip-path property. However, I have encountered an issue where this code only seems to work in Chrome. You can view the codepen demo here. Unfortunately, it appears that Firef ...

Using CSS in Rails based on a certain condition

My project involves creating an app with a specific view. Within this view, I must check a condition and if it is met, I need to color a table row accordingly. While the simplest solution would be to modify the header within the view, I prefer to keep al ...

Why is it not possible for me to change the font color to white?

To modify the font of the accordion heading to white, please check out the screenshot provided below. While the code functions properly in "fiddle", it seems that when I inserted the CSS snippet into a SharePoint 2013 page, the font color does not display ...

Set the height of the last child element to 100% in the CSS

Seeking assistance to adjust the height of the final list item to 100% in order to match the varying height of the right-floated div. ul.menu li:last-child {height:100%} Here is an example of my current situation: http://jsfiddle.net/kvtV8/1/ Any help ...

Tips for spinning HTML5 Canvas's background image and adjusting the zoom with a slider

As someone who is new to the world of coding, I have a few goals in mind: First and foremost, I want to create a canvas. I also aim to add a background image to the canvas. Importantly, this background image should be separate from any foreground images ...

Issue with ESRI-Leaflet not displaying in an Angular Typescript environment due to a failure to recognize vector data

I am facing an issue where I cannot display the map or utilize the search functionality provided by esri-leafleft. Below is the code snippet from the typescript file: import { Component, OnInit } from '@angular/core'; import { Title, Meta } from ...

"Alert box displaying error message is not appearing on the screen

In order to display an error message using a tooltip, I have hidden the tooltip by setting the style of a span with an id of demo to display:none. Then I use JavaScript's getElementById method to retrieve the value of the input field with an id of use ...

I'm struggling to activate the eventListener on several elements with the same className or ID. Unfortunately, only the initial child is being triggered in my current code implementation

Hello fellow developers, I'm facing an issue while working on a project. I have about ten menu items with the same ID, and I want to be able to edit each one when it is clicked. Here's what I tried using JavaScript: const menuElement = d ...

Retrieve individual data record from AngularFireDatabase

Welcome to my blog showcasing various screenshots: https://i.sstatic.net/cAtci.png My current focus is on retrieving a single course using its id, and I have the following code snippet for that purpose: Service: getSingle(uid: string) { return thi ...

What are the benefits of using AngularJS 2 in a PHP environment?

1) Is it possible to develop a project using php and angularjs 2 together? 2) Can I configure the development environment for Angularjs 2 with php? ...

Map / Area enveloped in darkness

I'm currently working on a map that includes an area, but I'd like to add a shadow effect around it. I'm struggling to figure out how to achieve this. <map name="map_bottom"> <area id="area_bottom" shape="poly" coords="0,0,0,37 ...

Obtaining the value of a dropdown in Angular 6 upon initialization, not just during a change event

Currently, I am working with a select dropdown that retrieves options data and values from an array using a loop. My goal is to extract the value of the selected dropdown when the page loads without requiring a change (in this case, "Recent"). Below is t ...

Organizing Angular Material Styles using Namespacing

In an attempt to develop reusable components with Angular 1.4.3 and Angular-Material 1.0.5, the goal is to seamlessly integrate these components across various applications. However, a challenge arises as the Angular Material CSS contains styling rules th ...

Enable the set body to have certain sections that are scrollable by setting overflow=hidden

I am currently working on a website that features the following structure: <body> <section></section> <section></section> ... </body> To prevent scroll bars on the body, I have set the CSS property body{overflow:hidden ...

Enhancing Images with Dynamic Captions Using JQuery

I have created a code to add image captions to different div blocks, and it works as intended. However, I am looking for ways to optimize the code and make it shorter. If you have any advice on how to improve it, please let me know! Thank you in advance. ...

How can I align a div in a vertical manner if it is displayed as a circle?

This is the creation I have come up with: This is the design I am aiming for: Below is the code I have written: <div id="OR"><span style=" vertical-align: middle;background:blue;">OR</span></div> Here is the corresponding CSS: ...