When the flex-grow property is set to 1, the height of the div extends beyond the space that

Here is an example of some HTML code:

.container {
  height: 100%;
  width: 100%;
  display: flex;
  flex-direction: column;
  padding: 10px;
  background-color: aqua;
}

.box {
  width: 100%;
  height: 100%;
  flex-grow: 1;
  background-color: cadetblue;
  display: flex;
  flex-direction: column;
}

.fill {
  flex-grow: 1;
  background-color: antiquewhite;
}

.middle {
  height: fit-content;
  background-color: azure;
  justify-self: flex-end;
}

.bottom {
  height: fit-content;
  background-color: darkgray;
  justify-self: flex-end;
}
<div class="container">
  <h3>Title</h3>

  <div>Some Stuff</div>

  <div class="box">
    <div class="fill">Fill in content here</div>

    <div class="middle">This is the middle part</div>

    <div class="bottom">This is at the bottom</div>
  </div>
</div>

The goal is to have the middle and bottom divs stack at the bottom of the screen, while the fill div fills the remaining space without causing a scrollbar or pushing the other divs off the screen. However, the current display does not achieve this as intended:

https://i.stack.imgur.com/oMlFo.png

It's important to note that the middle and bottom divs are hidden, and a scrollbar appears due to the fill div expanding beyond the available height.

To see a demo, check out this StackBlitz link: https://stackblitz.com/edit/angular-ivy-mwtwdg?file=src/app/hello.component.scss

Answer №1

I recently made updates to a lot of CSS code, so feel free to check it out.

When working on an Angular project, it is crucial to start with clean styling in the initial component (app component) and maintain this standard throughout all components.

View demo stackblitz

EDIT : explanation of comments

"The right approach" can be summarized as follows :

  • The html and body elements should occupy 100% of the page
  • The App component should fill 100% of its container and have display block property
  • Components requiring specific layouts (such as flex or grid) should be contained by their parent element or have fixed dimensions, along with display block property.

In Angular, components are not automatically set to display: block, leading to unpredictable layout issues as components do not adhere to expected constraints.

By ensuring every component has display: block (this can be automated using angular.json), you establish a more structured and predictable CSS approach.

In your scenario, the lack of display:block caused components to be unrestricted in size and positioning, compounded by problematic CSS like setting sidenav-container height to 100% without considering other elements like the toolbar.

To troubleshoot CSS issues in Angular, start with clean styling at the top level and systematically inspect and rectify any non-compliant components.

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

Ways to ensure that two divs have equal heights based on whichever one has the greater height using CSS

I need help with adjusting the heights of two divs inside a container div using CSS. Specifically, I want the height of the img_box div to match the height of the content_con div based on their actual content. For example, if the content_con div contains t ...

MailChimp consistently applies the "color: inherit !important" style to links, causing them to appear blue when viewed in Outlook

No matter how hard I try, MailChimp insists on styling any <a> tag with an href attribute to have color: inherit !important; text-decoration: inherit !important. This is causing my links to appear blue and underlined in Outlook, which is quite frustr ...

Make a <div> element that has a fixed size, but allows for scrolling text inside

I have tried searching the forum for a solution to my problem, but haven't found one yet. I am trying to create two "divs" with fixed height and internal scrolling. However, whenever I add text inside one of them, its height increases accordingly. Wha ...

Creating a display of divs that flow from left to right in each row, and then stacking the rows from bottom to top using CSS and jQuery

My current dilemma involves a collection of divs that must be displayed in a specific order, but with a rather intricate layout. Essentially, this is the structure of my HTML: <div> <div class="box">1 (first in list)</div> <di ...

showing a pop-up message when a specific javascript function is triggered

Here is a unique code snippet showcasing a customized dialog box created with HTML, CSS, and JavaScript. The dialog box is displayed when a button is clicked. <!DOCTYPE html> <html> <head> <style> /* Custom Modal Styles */ .modal { ...

What is the reason behind TypeScript rejecting the syntax of checkbox input elements?

When trying to use the following checkbox in TypeScript, I encountered a warning: <input type="checkbox" onClick={(event: React.MouseEvent<HTMLInputElement>) => { setIsTOSAccepted(event.target.checked); }} defaultChecked={ ...

An issue occurred at line 2, character 16 in the generateReport.service.ts file: TypeScript error TS2580 - The term 'require' is not recognized

I have a requirement in my app to generate a report in the form of a Word document with just a click of a button. Previously, I successfully accomplished this using the "officeGen" module in a separate project. You can find more information about the modul ...

Angular2- Retrieving configuration information during application launch

Implementing a method to load configuration data from an ASP.NET web API using HTTP at startup via APP_INITIALIZER. This approach was influenced by a discussion on Stack Overflow about loading configuration in Angular2 here and here. Snippet from app.modu ...

Strange Safari 15 bug causing unexpected transformations

Hey there, I'm a div with animation on scroll using GSAP. On Safari 15 (no issues below 15), something strange is happening - parts of the letters are leaving an afterimage on the sides. The code snippet I am using for this animation is: this.$refs.l ...

What is the process for customizing the image size of a WordPress RSS feed in pixels?

Is there a way to customize image sizes beyond the 'thumbnail', 'medium', and 'large' options? I tried setting width and height in the <img> tag within an RSS file, but it didn't work. Could it be a nested quotation ...

hover causing the table cell to act erratically

My table consists of three cells with widths of 30%, 40%, and 30% respectively. The table itself occupies 25% of its container, which can range from 1024px to 400px. The first cell contains a button labeled GALLERY. Upon hovering over the cell, the text c ...

Using jQuery to retrieve the nth child from a table after dynamically creating it with AJAX

When using AJAX in the code below, I fill and create simple data after retrieving it. $.ajax({ method: 'GET', url: '/analyzePage/searchTag/' + tagName, contentType: false, processData: false, success: function (data ...

Need help inserting an image into the div when the ngif condition is true, and when the ngif condition is false

Essentially, I have a situation where I am using an *ngIf condition on a div that also contains an image. This is for a login page where I need to display different versions based on the type of user. However, I'm facing an issue where the image does ...

Ways to retrieve the data within the tinymce text editor for seamless submission through a form

I am a beginner with TinyMCE and I am working on integrating the editor into my Laravel project. So far, I have managed to get it up and running, but I am struggling with retrieving the content from the editor and passing it to the controller for database ...

What is the best way to eliminate the space between columns?

I have a simple structure on BootStrap. <div class="container"> <div class="row"> <div class="col-md-4 blue-section" ><p>Some content</p></div> <div class="col-md-4 red-section"><p>Some content&l ...

Rotate a shape to form a Rhombus at the center

I used the transform CSS property to create a rhombus, but I noticed that the center point of the shape is off-center to the right rather than in the middle. Can anyone help me figure out how to fix this issue? You can view my code here. .rhombus{ width ...

Tips for updating the value.replace function for the "oninput" attribute within Angular 7

I need to modify an input based on a value from a TypeScript variable in the oninput attribute. This modification should only apply to English characters. In my HTML file: <input class="form-control" oninput="value=value.replace(r ...

The viewport scaling issue occurs when transitioning from landscape to portrait orientation

While developing a mobile version of my website, I have encountered an issue with the behavior when rotating my iPhone device. Everything looks fine in landscape orientation, but upon rotation back to portrait, the viewport remains stuck at the landscape s ...

Is it possible to utilize the $ symbol within the ngOnInit or constructor functions?

I recently encountered an issue while trying to use the dollar sign ($) in my constructor function, specifically within ngOnInit() and translate.instant. Here is a snippet of the code that caused the problem: declare var $: any; { var SelectedDevice = ...

What is the best way to end a Google OAuth session using Firebase on an Ionic 2 application?

My Ionic 2 app integrates Google Authentication using Firebase. I have implemented a logout button within the app that calls the Firebase unauth() method. However, this only disconnects the Firebase reference and does not terminate the Google OAuth session ...