Is there a way to achieve a straightforward three-column stacked layout in Bootstrap 5 that spans 100% of the viewport height?

Today I decided to try out Bootstrap 5 for the first time.

However, I am facing a challenge in creating a 3 stacked column layout with box-1, box-2, and box-3 on top of each other, taking up 100vh.

I have shared a redacted version of the code below, where you can see that it's supposed to be three boxes stacked vertically. While I've successfully achieved this using CSS Grid and Flexbox, I'm struggling to do the same with Bootstrap.

Here are the methods I've attempted so far without success:

  1. Setting body and html height to 100vh
  2. Setting container height to 100vh – this results in each box taking up 100vh individually, causing an overflow issue
  3. Creating a wrapper class around the body content and setting its height to 100vh
  4. Repeating steps 1 to 3 with a utility class vh-100

If anyone has any suggestions or solutions, please let me know!

Thank you

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/contact/a6d4f8ede9"><span class="__cf_email__" data-cfemail="87e5e2e2f5e2e7e1f2c3b097caecabe6">[email protected]</span></a>/dist/css/bootstrap.min.css" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8t94WrHftjDbrCEXSU1oBoQyl2QvZ6jIW3" crossorigin="anonymous">

<body>
  <section class="container box-1">
    <div class="row">
      <div class="col">
      </div>
    </div>
  </section>

  <section class="container box-2">
    <div class="row">
      <div class="col">
      </div>
  </section>

  <section class="container box-3">
    <div class="row">
      <div class="col">
      </div>
    </div>
  </section>
</body>

Answer №1

It appears that you can greatly simplify this design. If there is only one row or column in each container, it may not be necessary to have multiple rows or columns. In fact, using a basic flex column as outlined in the documentation should suffice.

/* all styles for demo only */

.d-flex {
  background: #eee;
}

.box-1:nth-child(even) {
  background: pink;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2b4944445f585f594a5b6b1e051a0518">[email protected]</a>/dist/css/bootstrap.min.css" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">

<body>
  <div class="container d-flex flex-column vh-100 p-0">
    <section class="box-1 flex-fill">Section</section>
    <section class="box-1 flex-fill">Section</section>
    <section class="box-1 flex-fill">Section</section>
  </div>
</body>

If you do find the need for containers and inner structure, simply move the flex-fill class out to the rows (and use just one container). The result will remain the same.

/* all styles for demo only */

.row {
  background: #eee;
}

.row:nth-child(even) {
  background: pink;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ceaca1a1babdbabcafbe8efbe0ffe0fd">[email protected]</a>/dist/css/bootstrap.min.css" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">

<body>
  <div class="container d-flex flex-column vh-100">
    <div class="row flex-fill">
      <div class="col">
        <section class="box-1">Section</section>
      </div>
    </div>

    <div class="row flex-fill">
      <div class="col">
        <section class="box-1">Section</section>
      </div>
    </div>

    <div class="row flex-fill">
      <div class="col">
        <section class="box-1">Section</section>
      </div>
    </div>
  </div>
</body>

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

Expansive dropdown menu stretching across the entire width, yet the content within restricted to a width of

I have recently made some updates to our website's dropdown menu, expanding the results displayed. However, I would like the dropdown contents to fit within the width of our page. https://i.sstatic.net/aR0Qm.jpg https://i.sstatic.net/e61Ig.jpg I ha ...

Having trouble getting rid of the border-bottom?

I have been attempting to customize the appearance of the React Material UI tabs in order to achieve a design similar to this: https://i.stack.imgur.com/tBS1K.png My efforts involved setting box-shadow for the selected tab and removing the bottom border. ...

What is the best way to reset the selected option in Vue.js when clicking on a (x) button?

Is there a way to create a function or button specifically for clearing select option fields? I attempted using <input type="reset" value="x" /> However, when I clear one field, all fields end up getting cleared. Should I provide my code that incl ...

Combine two FontAwesome icons in a stacked manner

Is there a way to group 2 icons together and display them one above the other? I attempted to use the fa-stack class, but the images are overlapping. How can I achieve this layout? <span class="fa-stack fa-lg"> <i class="fa fa-envelope fa-stack ...

The .find() function conveniently jumps over the table directly following its parent element

After clicking on Inner Add Row, the correct row is added from the .charts-series table. However, when I click on Outer Add Row, a row from the .charts-series table is added instead of one from the .charts table. Here is the link to the example: http://jsf ...

Is Consistency Possible with CSS Transition Direction?

Take a look at this example: https://codepen.io/jon424/pen/XWzGNLe In the provided code snippet, there is a button that can toggle the visibility of an image. When clicked, the image disappears from bottom to top and reappears when clicked again. The use ...

I need the sidebar to be visible across all interfaces

https://i.stack.imgur.com/iEgAF.png I have developed a website for employee monitoring with six interfaces. The first interface is for sign-up, the second for logging in, the third for creating projects, the fourth for displaying projects, the fifth for c ...

Tips on merging HTML node lists from various `getElement`s

Is there a way to combine HTML elements and extract values using array methods? I am struggling to merge them as a nodeList. I tried using get elements and array.unshift to consolidate elements into one variable. var elemsLabel = document.querySelecto ...

Looking for some guidance and feedback on how to improve a workflow utilizing Bower, Grunt, and Bootstrap

So far, I've taken the following steps: Installed Bower globally using npm Installed Grunt globally using npm Set up a folder for my project ("test") Created a bower.json file (could have used bower init) with "bootstrap": "latest" as the sole depen ...

The tip display script is unable to revert back to its original content

I managed to show a block of text in a td after a mouseover event, but I want to revert back to the original content on mouseout/mouseleave. The code I used is below. Please help. I am getting an undefined error when running the code. I suspect the issue l ...

Having issues with column offsetting in Bootstrap v4.0.0-beta

While using Bootstrap 4 Beta (Bootstrap v4.0.0-beta), I encountered an issue with offsetting columns. Previously, I used offset-md-* and it worked fine. However, this feature has been removed in BS4 Beta as per the documentation. The new method suggested i ...

I am struggling to get the images aligned properly on my HTML page. Can someone please advise on how to fix this issue?

On my HTML page, I have 2 div fields. Within each field, there are 5 images listed sideways. The issue is that the images in the div below are not lining up properly side by side. Given my limited frontend knowledge, how can I align them correctly? Here&a ...

Leveraging jQuery to extract the value from a concealed form field

Seeking assistance with a jQuery issue... I am attempting to use jQuery to retrieve the values of hidden fields in a form. The problem I am facing is that there are multiple forms displayed on the same page (result set items for updating), and the jQuery ...

Offspring element overrides styling of its parent

#popBox{ width:100%; height:100%; position:fixed; left:0; top:0; border-collapse:collapse; background:black; opacity:0.8; display:none; } <table id="popBox"> <tr> <td></td> <td></td> ...

Is there a way for me to incorporate a feature where the user has the option to choose the number of passwords they would

I created a password generator for my company and now I want to implement the feature where the user can choose how many passwords they want. My attempt at using str_repeat ($output , $password_amount ) resulted in duplicate passwords being generated, mak ...

What is the best way to conceal the border and background color of the dropdown arrow in an HTML <select> tag?

Upon browsing the Mozilla homepage, I noticed a peculiar element in the center - a <select> option with an arrow lacking border and background color. In contrast, when visiting the Facebook sign-up page, the drop-down arrow adheres to the Windows sta ...

Use CSS3 to hide the <li> elements initially and make them appear when the <li> is clicked on

Click here How can I hide the "subline" line from the list and make it visible when the user clicks on the "sub" line, pushing the other lines down? I'm hoping for a solution that doesn't involve using Js or JQuery. Thank you in advance! ...

What is the process for detaching and attaching click animations using the on() method?

I am encountering an issue with a recursive loop that executes a simple animation. These animations are controlled by the page load and clicking on controls .carousel_item. Click here for live sample JSFiddles for demonstration purposes Challenge: The pr ...

Adding space between the heading and the text underneath by placing a margin between h2

I am dealing with a situation where I have an <h2 class="landing-panel-title> containing a <span class="landing-panel-icon-right ion-ios-search-strong>. The second class on the span is from an icon font called ionicons. Despite this, it may not ...

What is the best way to design a content page with linked boxes to various arrays in PHP?

How can I create a PHP menu template that navigates to different pages? I am new to PHP and still learning. I want to achieve something similar to this image: https://i.stack.imgur.com/ylfe8.jpg I have the code for the navigation bar, but I need help crea ...