Can rows be nested within the d-flex class in Bootstrap 4?

(I found a related inquiry here, however, my current skill level does not allow me to implement it with Bootstrap just yet)

My goal is to create a section on the webpage between the "header" and "footer" (referred to as "body"), which should include:

  • a fixed section at the top, like BS4 "row",

  • variable content made up of multiple BS "rows", aligned vertically in the middle of the remaining body space

Is it possible to achieve this responsively without using JavaScript, solely relying on Bootstrap 4 CSS?

I have attempted the following:

  <body> 
    <div id="root" class="container">
     <div style="height: 100%;">
      <div><h1>HEADER</h1></div><hr>
      <div style="min-height: 60%;">
        <div class="h100">
          <div>some badge</div><br>
          <div>
            <div class="row justify-content-between">
              <div class="col-3">Item #2</div>
              <div class="col-3 text-right">
                <div>some stats</div>
              </div>
            </div>
            <div class="">
              <div class="row justify-content-center">
                <div class="col text-center"><h3>THIS SHOULD BE IN THE MIDDLE OF A BLANK SPACE</h3></div>
              </div>
              <div class="row justify-content-center">
                <div class="col-4 text-right"><button class="btn btn-link">it's just below and left</button></div>
                <div class="col-4 text-left"><button class="btn btn-link">it's just below and right</button></div>
              </div>
            </div>
         </div>
        </div>
      </div><hr>
      <div class="footer">FOOTER</div>
     </div>
    </div>
  </body>

(https://jsfiddle.net/f93mhdbr/) However, when I add "d-flex" to the "body" div or any of its children, the previous layout based on "row"/"col" gets messed up! (see https://jsfiddle.net/f93mhdbr/2/)

This might be because Bootstrap itself uses Flexbox for columns and rows, but is there any alternative solution available?

I will continue working on refining this question, I acknowledge its lack of detail, but currently, I am struggling to figure it all out...

UPDATE: included links to examples I was attempting to replicate

Answer №1

If you want your variable element to grow and fill the remaining height of its container, you should utilize the flex property instead of using flex-grow. Additionally, make sure to set align-items-center on the element to align it along the x-axis.

To see a demonstration, check out this Fiddle. I've added background colors to make it easier for you to visualize the space each element occupies.

You can specify fixed heights for the header, footer, and content-top. The heights of content and content-remaining will adjust responsively as they have flex-grow: 1 applied to them. An example is available here.

In regards to the flexible items inside the container wrap, setting a min-height: 100-vh on the container allows the content element to expand relative to the other flexible items. The same principle applies to content-remaining, except its parent is the content element rather than the wrap container.

To address the IE bug related to the min-height property with flex items, refer to this known issue. A workaround involves wrapping the affected elements in a separate flex container.

I hope this explanation clarifies things for you. If you have any further questions, please feel free to leave a comment below.

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

`When utilizing $routeParams, the CSS fails to load`

Whenever I use parameters in ngRoute and go directly to the URL (without clicking a link on the site), the CSS fails to load. All my routes are functioning properly except for /chef/:id. I utilized yeoman's angular generator, and I am running everythi ...

Unable to scroll when utilizing ng-html-bind functionality

My device specifications: $ ionic info Your system details: Cordova CLI: 6.2.0 Gulp version: CLI version 3.9.1 Gulp local: Ionic Framework Version: 1.2.4 Ionic CLI Version: 2.0.0 Ionic App Lib Version: 2.0.0-beta.20 OS: Distributor ID: LinuxMint Desc ...

What is the best way to add a class to the initial HTML element in my specific scenario?

Currently utilizing the angular framework in my application. Desire to assign a specific class to only the initial element within my ng-repeat iteration. <div class='initialOnly' ng-repeat = 'task in tasks'>{{task.chore}}</di ...

Adjust the margin of FormHelperText within a FormControl specifically for a Select component in Material-UI

I'm currently facing a challenge where I need to add marginLeft of 8px to FormHelperText. However, I have not been successful in doing so within the MuiInput formControl rule or in MuiSelect. Here is the React code snippet: <FormControl error clas ...

I am facing an issue where new tags are not being created when I pre-fill values in the tags input field on Bootstrap

When working on the Product Edit Page, I successfully displayed the old data that was selected previously. However, I am facing an issue with adding new tags. The new tags do not appear when I press enter or space after typing in the input field. It is pos ...

Tips for adjusting the size of a container to fit its child element in a flexbox layout, where the flex-direction is set to column

Below is the functional code: .container{ display: flex; background-color: lightgreen; justify-content: center; alighn-item: center; } .child{ margin-left: 10px; height: 200px; background-color: yellow; display: flex; flex-direction: ...

Easy steps for aligning text with shiny html

Looking at the code below, I was able to successfully align the bullet-point text in the popover when hovering over the information circle. However, I am still struggling to justify-align its header right above it, as seen in this image. When I remove the ...

Tips for creating a clickable image inside a span button

I am trying to create a clickable button that includes a span with a .png image inside. Currently, the button only responds when I click around the image, not directly on it. I have searched for solutions but haven't found one that addresses my specif ...

The canvas element on a simple HTML webpage is constantly set to a size of 300x150

In an attempt to simplify my problem, I have created a basic HTML document with a <canvas> element: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <style> body { border: 1px solid #ff5500; ...

Changing the class when a checkbox is selected using JQuery

I’m working on a bootstrap switcher and I want to change the panel color from grey to green when the checkbox (switch) is checked. I had it working before, but after updating the switcher, it no longer functions properly. Here is the main code for the s ...

pressing the button again will yield a new outcome

I am looking to disable a button (material ui) when it is clicked for the second time by setting disabled={true}. Unfortunately, I have not been able to find any examples related to this specific scenario on StackOverflow. <Button onClick={this.s ...

Style the div element with CSS

Is there a way to style a div element within an HTML document using Sencha framework? I have specific CSS properties that I would like to apply to my div. #logo{ position:absolute; top:20%; left:0%; } Below is a snippet of my Sencha code: Ex ...

Implement a captivating hover effect on every single element within a particular class

I created a basic website with the following design: However, there is an issue with the hover effect. It only works on the specific area where the mouse pointer is located (here ipsum). My intention was for the hover effect to work on all elements. To fi ...

What is the best method for inserting a URL link using jQuery within a CSS element?

Check out this code snippet: <span class='maincaptionsmall'> Test </span> Due to certain ajax and jquery scripts on my page, I am unable to use HREF as a link. In other words, the following code won't work: <span class=&ap ...

Can someone assist me with positioning the image card to overlay the top border of the card using bootstrap, or is it only achievable with CSS?

https://i.sstatic.net/Ef69i.png Is there a way to use Bootstrap to position the image card to overlay the top border of the card without using custom CSS? I've attempted to achieve this with the following custom CSS: style="margin: -50px 70px;& ...

Issues with custom logo and menu/sidebar toggle on Wordpress

Hello everyone, I am currently facing some difficulties with my new WordPress blog that utilizes the Skilt-Theme. Specifically, I'm having trouble with the custom-logo and sidebar-toggle features. When there is no logo present, you can see the layout ...

Achieving fixed width and automatic height for images in Next JS: a guide

I am struggling to showcase a list of images with a fixed width while utilizing the original image height set at 100%. A similar inquiry can be found here, yet it remains unanswered. I have gone through the responses shared here and attempted them. The im ...

Alter attribute with an impact

I am looking for a solution to switch the image source using attr, while also incorporating a fade effect in the process. I have attempted to implement one of the suggestions from another post, but it is not producing the desired outcome. Current Appearan ...

Issue with custom checkbox not changing when bootstrap collapse occurs

I've been searching for a solution and experimenting with different methods, but I just can't seem to make it work. Below is a CodePen example that showcases a custom checkbox with a toggle function to show/hide a div when checked, along with a ...

How is it possible for a JavaScript variable sharing the same name as a div Id to automatically pass the div?

This is just ridiculous. Provided HTML <p id = "sampleText"></p> Javascript var sampleText = "Hello World!"; Execution console.log(sampleText); // prints <p id = "sampleText"></p> How is this even possible? I ...