Bootstrap flexbox, 2 row, 1 column layout and align contents

Viewed 268

I want to have a full width 2 row, "1 column" layout, that takes up the entire viewport. The top row should have it's contents on the bottom of that row, and the bottom row should have it's contents on the top of that row.

Using some examples from bootstrap, I was able to achieve this: https://codepen.io/afagard/pen/QWpJWze

However, I am not sure if I am doing it correctly even though it looks as expected. Specifically, I tried to set the container to 100vh but that did not result in any changes to flexboxes so I've got each row at 50vh. I mostly do backend work and am trying to learn flexboxes.

enter image description here

1 Answers

Here is an example of a flexbox solution using just the bootstrap classes and no additional css:

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous">


<div class="container-fluid p-0 vh-100 d-flex flex-column text-center">
  
  <div class="flex-grow-1 d-flex flex-column bg-primary">
    <div class="mt-auto">
      Top half
    </div>
  </div>
  
  <div class="flex-grow-1 d-flex flex-column bg-secondary">
    <div class="mb-auto">
      Bottom half
    </div>
  </div>
  
</div>

Related