HTML elements with flex properties are not merging together when using a flexbox layout with a flex value of 1

I recently created a landing page using the HTML code provided below.

Additionally, I have taken the time to prepare a bootply example that illustrates how the pink div extends too far and fails to cover the entire screen as intended. You can view this demonstration here.

https://www.bootply.com/bYlAS71OWw

The issue I am facing relates to a pink section on the page that is supposed to adjust its size to fill the available space in the browser without causing a scrollbar to appear.

It seems that the height of the header and breadcrumb elements is not being properly accounted for in the overall layout calculation.

  • The heading is contained within a flex col,
  • The .breadcrumb element also uses flex properties.

As a result, the page ends up displaying a scrollbar due to the combined height of the heading and breadcrumb area.

<app-dashboard>
  <div class="app-body">

    <main class="main">
      <ol class="breadcrumb">
        <li class="breadcrumb-item">
          <a href="#/">Home</a>

        </li>
        <li class="breadcrumb-item active">
          <span tabindex="0">Property Locations</span>
        </li>    
      </ol>

      <div class="container-fluid d-flex h-100">
        <router-outlet></router-outlet>
        <ng-component class="d-flex flex-grow w-100">
          <div class="row w-100">
            <div class="col">
               HEADING    
            </div>
            <div class="d-flex flex-grow bg-pink-300 h-100 w-100">
              THIS SHOULD GROW, BUT NOT CREATE A SCROLLBAR
            </div>
          </div>
        </ng-component>
      </div>
    </main>

  </div>
  <footer class="app-footer">
    <span>
      <a href="..."></a>Pander.</span>
    <span>
      <i class="fa fa-fw fa-code-fork"></i>
    </span>
  </footer>
</app-dashboard>

The CSS I am using for flex-grow is:

.flex-grow {
  flex: 1 0 auto;
}

Answer №1

To better understand the concept, let's simplify the example by removing any custom tags. It seems like you are aiming to utilize flexbox, but there are a few key points to consider:

  1. Remember that what grows and shrinks is the flex item, not the flex container. An element only becomes a flex item when its immediate parent is a flex container. In your case, the div with the class bg-pink-300 is not a flex item because its immediate parent is just a row.
  2. It seems like you are trying to make your div automatically fill the available vertical space using flexbox. However, all your flex containers are horizontal, so vertically, you are relying on percentage height for now.

In general, your main container should be a vertical flexbox that defines the total vertical space without overflowing. Your breadcrumb, header, and pink div should be placed in this container as flex items. Breadcrumb and header do not need to grow or shrink, so they should have flex: none. The pink div can have flex: 1 1 0 to allow it to expand and contract within the main container after the breadcrumb and header have been accommodated.

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 are the steps to create a navbar positioned below an image?

I have my navbar on another page, but I would like to center it directly under the logo or image. My align-items property doesn't seem to work, so I've had to set the height in the .logo class. Is there any other method I can use to achieve this? ...

What steps can be taken to resolve the unexpected padding issue in a Bootstrap form?

https://i.sstatic.net/iSz2e.png <form class="form-inline"> <div class="form-group"> <div class="input-daterange input-group" id="datepicker"> <label>Beginning:</label> <input type="text" ...

Tips for avoiding a ligature occurrence in a specific location

I am a fan of ligatures in general, as they improve readability. I want to implement them across all my HTML pages. However, there is this one word Hanftierheft (which is German and a compound word made up of Hanf, Tier, and Heft). I specifically do not w ...

Migrating from PHP/MySQL to PDO: A Smooth Transition

I am a beginner in PHP/MySQL and I have some queries. I was watching a YouTube tutorial on creating a basic dynamic website that retrieves data from a MySQL database and displays it on a single PHP index page. I followed the tutorial up to the point wher ...

What could be causing the icon link to not show up in Bootstrap 4?

Currently, I am engrossed in reading the book titled "ASP .NET MVC 5." However, I have hit a roadblock. The author utilizes Bootstrap 3 in the book, but the newer version of Bootstrap contains some modifications that are causing me difficulties in solving ...

Ensuring that the two columns in a responsive grid have equal heights is essential for maintaining a

I am currently working on a responsive website with a main content area (.content-wrapper) and a sidebar area (.search-listing). My goal is to make sure that both columns have the same height. I attempted to achieve this using the following jQuery code: j ...

Looking to find the video code in the page source and figure out how to get the video to play

I have a requirement where I must embed the video code directly in a blog post. After figuring out the necessary code for the video and saving it in a html file named video.html, I encountered an issue when trying to upload the file to the blog. Only the ...

When I click the submit button in HTML PHP, the text in the text field disappears. How can I make sure the text stays

I am facing an issue with the functionality of my form's submit button. When I click the button, the text in the text field disappears, but I need it to remain for another button that requires it. These two buttons are part of different functions, and ...

Troubleshooting a Label Overlapping Problem in Materialize CSS

I've been working on a Materialize project and encountering an issue with pre-filled values in text boxes. Here is a snapshot of the problem: https://i.stack.imgur.com/u13jT.png <div class="input-field col s12 m6"> <input class="" id="us ...

What CSS property can be used to make short words wrap to the next line?

Is it possible to automatically identify if a line of text ends with a short word and then move it to the next line, so that the text flows smoothly? This would ensure a more organized layout. For instance, I envision the following text: Cascading Style ...

Can theme changes be carried over between different pages using Material UI?

I've encountered an issue with MUI 5.14.1 where I'm getting an error every time I attempt to save themes across pages using localStorage. Any suggestions on how to resolve this problem or recommendations on a different approach would be greatly a ...

Utilizing a media query to execute a <script> exclusively on desktop devices

I am attempting to only run <script type="text/javascript" src="#" data-cfasync="false" async="async"></script> on desktop devices. I experimented with <style> @media screen and (max-width: 600px) { ...

Utilizing Three.js to load JSON models

Having just dipped my toes into the world of WebGL, I recently attempted to showcase a JSON model using three.js in Firefox. However, all I encountered was a blank screen with the error message "NS_ERROR_DOM_BAD_URI: Access to restricted URI denied" with ...

Does Ext js have a monochromatic theme of blue running through everything

While the blue color may give off a nice office ambiance, it's important to have variety in the appearance of different applications. Is it simple to customize the look in ext js? ...

What is the best way to select the <span> element following an HTML tag?

Is there a way to target the first child of a span after a specific HTML tag? Here is an example of my markup: <div class="gad-help"> <a href="#">AdWords Guide<br><span>ensure best results</span></a> </div> H ...

Animation in Three.JS not visible in Chrome version 61 on Mac OS X Sierra

I've been going through some beginner tutorials for three.js and I'm facing an issue where I only see a red background when I try to run the code I created in Atom on Chrome (Version 62.0.3202.75 (Official Build) (64-bit)), Mac OS X (macOS Sierra ...

Require limitation of the maximum value input from the keyboard

I'm working on some HTML code that allows me to limit a number input using the up and down keys. However, I also need to restrict manual entry from the keyboard. Currently, the input field accepts any number entered through the keyboard. <input ...

Is it possible to replace JavaScript files that are included in my index page if I am utilizing conditional comments specifically for IE9?

My website works perfectly in all browsers, except for IE9. After some investigation, I discovered that the issue lies with a jQuery plugin called multilevelpush.js. While it works great on other browsers, it simply won't cooperate with IE9. Upon fur ...

Generating live link for iteration using ng-repeat

I am currently facing an issue with my table of content in the tableofcontent.html file. Each article title is clickable, but when I click on a link, the data does not populate correctly in the articles.html page. How can I ensure that the data for each li ...

Having trouble converting svg to png, thinking it might be due to discrepancies in svg elements

I am facing a puzzling issue where two different SVG elements are causing my JavaScript to work in one scenario but not the other. I have replaced the SVG elements in both examples, and surprisingly, only one works while the other does not. You can view th ...