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

Strategies for incorporating child element margins within a parent container with overflow scroll

My container has a fixed width causing its children to overflow and require scrolling. Each child element (.box) has a margin-right: 10px. The margin is visible on all elements except the last one, where it is cut off at the edge of the element. I want to ...

How can I wrap text in Angular for better readability?

I've created a calendar in my code that displays events for each day. However, some event descriptions are too long and get cut off on the display. Even after attempting to use Word Wrap, I still can't see the full text of these events unless I c ...

Having trouble with IE7 - unable to interact with elements below popup form

<script type="text/javascript">var switchTo5x=true;</script> <script type="text/javascript" src="http://w.sharethis.com/button/buttons.js"></script> <script type="text/javascript">stLight.options({publisher:'b42661f5-2dc5 ...

Display the HTML content retrieved from the SailsJS Controller

Exploring the world of SailsJS, I am on a mission to save HTML content in a database, retrieve it, and display it as rendered HTML. To achieve this goal, I have set up a sails model and a controller. This is what my model looks like: attributes: { ht ...

Make fun of the server's response, even when the server is not responding

Here are some things I have learned (Please correct me if any information is incorrect, thank you :)): HttpInterceptor functions similarly to Aspect-oriented programming in certain ways; We can manipulate the httpOptions for requests; Modifying response ...

Error in MatSort implementation - Argument cannot be assigned

I'm having trouble figuring out how to implement the Mat-Sort functionality from Angular Material. When I try to declare my variable dataSource, I get the following error: Argument of type 'Observable' is not assignable to parameter of type ...

Replace the bullet icon with a double quote symbol

My HTML List needs a different look - I want to change the bullet icon into a double quote icon. A website that I found interesting is this one. Here's the CSS code I have: .listStyle li:before { list-style: none; content: "\00BB"; } < ...

What is the method to deactivate multiple links using jQuery?

Below is the HTML code: <a title="Login" data-href="/MyAccount/Access/Login" data-title="Admin" data-entity="n/a" id="loginLink" class="nav-button dialogLink"><b>Login</b></a> <a title="Register" data-href="/MyAccou ...

Expanding the background further than the parent's width using HTML and CSS

I am looking to extend the background color or image to mimic the appearance of the example at the bottom in this jsfiddle Same code but showcased here: Example1: <div class="fixed_width"> <div class="header">Header</div> <div ...

Preventing ReactJS tooltips from exceeding the boundaries of the screen

Here is a simple demo showcasing blocks with tooltips that appear when hovered over. However, there seems to be an issue with the functionality. The tooltip should ideally be displayed either from the left or right side of the block. To determine the size ...

How can you display a message if a variable is not found in a MySQL table?

My current code is set up to display links from a MySQL database where the movie_id matches the GET id. However, I would like to update it so that if no links are found with that movie_id, it will instead echo a message saying "No links were found." < ...

Comparison between Bootstrap 4 and Firefox Preload Error

Hello fellow front end developers who are experiencing an issue with CSS preload in Firefox versions above 74.0. I have encountered a problem with the following code snippet: <link rel='preload' as='style' onload="this.onload=null; ...

retrieve the height value of a div element using AngularJS

I'm having trouble retrieving the updated height of a div using AngularJS. It seems to only provide the initial value and does not update as expected: vm.summaryHeight = $(".history-log-container").height(); console.log(vm.summaryHeight);//always dis ...

JavaScript is submitting an incorrect HTML form

I have a PHP script that retrieves items from a database and allows users to vote on them. Each item is associated with an HTML form containing an input text field and a submit button to enter the score. I also have a jQuery script on the same page that up ...

Creating Beautiful Math Equations with LaTeX in EaselJS

Can MathJAX or a similar tool be integrated into an EaselJS DisplayObject? I am looking for alternative options. I want to render text like $$ 5 + 3 - 3 = 5 $$ on a canvas that serves as an EaselJS stage. Ideally, I hope to achieve this using the Text Cl ...

TSLint warning: Duplicate identifier detected - 'err'

Currently facing an issue with tslint displaying the following error Shadowed name: 'err' Providing the code snippet for reference fs.readdir(fileUrl, (err, files) => { fs.readFile(path.join(fileUrl, files[0]), function (err, data) ...

Understanding the usage of jQuery transitionend to prevent interruptions in CSS animations

I found a similar thread on StackOverflow but I'm struggling to apply it in my current scenario. The Setup (Welcome Ideas) I've developed a jQuery slider that will have multiple instances on one page, each containing an unknown number of childr ...

Dreamweaver constantly combines an external CSS file with locally stored CSS when running on a local server

When I used Dreamweaver CS5, XAMPP Server, and PHP files in the past, I encountered an issue. The websites within my htdocs folder seemed to be pulling a specific website's CSS file. In 'Live View,' I could see all external .css and .js file ...

Changing the width of an SVG path from 0 to 100% using CSS

I have an SVG design of wires that I want to animate the width from "0 to 100%", but I'm having trouble achieving this effect. It's easy to do with a div element, but not with an SVG image. Below is my code snippet: svg path { animation: f ...

issues stemming from the css of leaflets

This is my first time using leaflet and I am encountering a CSS issue. I'm not sure if there is another CSS file for leaflet, but whenever I try to adjust its position, it changes unexpectedly. I have a floating nav bar that should appear when scroll ...