Creating a sleek and functional full-height drawer with Bootstrap 4

I am currently developing an app that utilizes Bootstrap 4 and the material design framework. My goal is for this app to fill the entire screen and incorporate the drawers provided by the framework. While I have successfully implemented a flexbox to make the app fill the screen, I am facing a challenge in getting the drawer to occupy all available height. You can observe this issue in this Fiddle example. The code snippet featured in the Fiddle is as follows:

<div id="app" class="d-flex flex-column h-100">
  <nav class="navbar sticky-top banner">
    <a class="navbar-brand" href="#">My App</a>
  </nav>

  <div class="d-flex flex-column flex-grow">
    <div class="h-100 flex-grow">
      <div class="bmd-layout-container bmd-drawer-f-l bmd-drawer-overlay">
        <div id="appDrawer" class="bmd-layout-drawer bg-faded">
          <div class="container">
            <header>Hello</header>
            <p>
              This is a longer block of information text.
              Regardless of how long this block of text is,
              the drawer should extend all the way to the footer.
            </p>
          </div>
        </div>

        <main class="bmd-layout-content">
          <div class="container">
            <h1>
            Hello
            </h1>

                <button class="btn btn-primary btn-raised" data-toggle="drawer" data-target="#appDrawer">Show Info</button>

          </div>
        </main>
      </div>
    </div>


    <footer>
      <p>Thank you for visiting!</p>
    </footer>
</div>

Could someone please advise me on how to ensure that the drawer occupies the full height between the nav and footer sections?

Appreciate your help!

Answer №1

To create a responsive layout, you can transform the parent element containing .bmd-layout-container into a flex container with a column direction and then apply flex-grow: 1 to the dynamically generated .bmd-layout-canvas class.

$(document).ready(function () { $('body').bootstrapMaterialDesign(); });
body, html {
    height: 100%;
}

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

.bmd-layout-canvas {
  flex-grow: 1;
}
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<link href="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="670508081314131506174a0a061302150e060b4a0302140e0009275349564956">[email protected]</a>/dist/css/bootstrap-material-design.min.css" rel="stylesheet"/>
<script src="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="fc9e9393888f888e9d8cd1919d88998e959d90d198998f959b92bcc8d2cdd2cd">[email protected]</a>/dist/js/bootstrap-material-design.js"></script>
<div id="app" class="d-flex flex-column h-100">
  <nav class="navbar sticky-top banner">
    <a class="navbar-brand" href="#">My App</a>
  </nav>
  
  <div class="d-flex flex-column flex-grow">
    <div class="h-100 flex-grow d-flex flex-column">
      <div class="bmd-layout-container bmd-drawer-f-l bmd-drawer-overlay">
        <div id="appDrawer" class="bmd-layout-drawer bg-faded">
          <div class="container">
            <header>Hello</header>
            <p>
              This is a longer block of information text.
              Regardless of how long this block of text is,
              the drawer should extend all the way to the footer.
            </p>
          </div>
        </div>

        <main class="bmd-layout-content">
          <div class="container">
            <h1>
            Hello
            </h1>
            
                <button class="btn btn-primary btn-raised" data-toggle="drawer" data-target="#appDrawer">Show Info</button>

          </div>
        </main>
      </div>
    </div>
    

    <footer>
      <p>Thank you for visiting!</p>
    </footer>
</div>

Check out this demo on JSFiddle - https://jsfiddle.net/n9c4Lbqa/

Answer №2

To adjust the height dynamically, consider using vh units. Each 1vh corresponds to 1% of the viewport height (100vh equals 100%). Utilize the calc function in CSS to customize the element to fill the remaining height exclusive of other components or elements.

.custom-element {
  height: calc(100vh - 60px);
}

Modify the value 60px based on your layout requirements to ensure proper spacing and alignment.

Answer №3

Perhaps not the most elegant solution, but it gets the job done.

$(document).ready(function () { $('body').bootstrapMaterialDesign(); });
#app {
  height: 100vh;
}

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

.fill {
  height: 100%;
}

.test-wrap {
  position: relative;
}

.test {
  position: absolute;
  top: 0px;
  bottom: 0px;
  left: 0px;
  right: 0px;
}
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/js/bootstrap-material-design.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" />
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" />
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/css/bootstrap-material-design.min.css" />

<div id="app" class="d-flex flex-column fill">
  <nav class="navbar sticky-top banner">
    <a class="navbar-brand" href="#">My App</a>
  </nav>

  <div class="flex-grow p-r test-wrap">
    <div class="h-100 flex-grow test">
      <div class="bmd-layout-container bmd-drawer-f-l bmd-drawer-overlay">
        <div id="appDrawer" class="bmd-layout-drawer bg-faded">
          <div class="container">
            <header>Hello</header>
            <p>
              This is a longer block of information text.
              Regardless of how long this block of text is,
              the drawer should extend all the way to the footer.
            </p>
          </div>
        </div>

        <main class="bmd-layout-content">
          <div class="container">
            <h1>
            Hello
            </h1>

                <button class="btn btn-primary btn-raised" data-toggle="drawer" data-target="#appDrawer">Show Info</button>

          </div>
        </main>
      </div>
    </div>
  </div>


  <footer>
    <p>Thank you for visiting!</p>
  </footer>
</div>

Here's another way using flex:

$(document).ready(function () { $('body').bootstrapMaterialDesign(); });
#app {
  height: 100vh;
}

.flex-grow {
  flex-grow: 1;
}
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/js/bootstrap-material-design.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" />
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" />
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/css/bootstrap-material-design.min.css" />

<div id="app" class="d-flex flex-column">
  <nav class="navbar sticky-top banner">
    <a class="navbar-brand" href="#">My App</a>
  </nav>

  <div class="flex-grow d-flex test-wrap">
    <div class="flex-grow test"><!-- removed h-100 -->
      <div class="bmd-layout-container bmd-drawer-f-l bmd-drawer-overlay">
        <div id="appDrawer" class="bmd-layout-drawer bg-faded">
          <div class="container">
            <header>Hello</header>
            <p>
              This is a longer block of information text.
              Regardless of how long this block of text is,
              the drawer should extend all the way to the footer.
            </p>
          </div>
        </div>

        <main class="bmd-layout-content">
          <div class="container">
            <h1>
            Hello
            </h1>

                <button class="btn btn-primary btn-raised" data-toggle="drawer" data-target="#appDrawer">Show Info</button>

          </div>
        </main>
      </div>
    </div>
  </div>


  <footer>
    <p>Thank you for visiting!</p>
  </footer>
</div>

Answer №4

If you're looking for a solution, here's one that could be effective:

Try it out on Fiddle: https://jsfiddle.net/aq9Laaew/105279/

CSS Styles

body, html {
  height: 100%;
  margin: 0;
}
#app {
  min-height: 100%;
}

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

.push {
  height: 50px;
}

HTML Markup

<div id="app" class="d-flex flex-column h-100">
  <nav class="navbar sticky-top banner">
    <a class="navbar-brand" href="#">My App</a>
  </nav>

  <div class="d-flex flex-column flex-grow push">
    <div class="h-100 flex-grow">
      <div class="bmd-layout-container bmd-drawer-f-l bmd-drawer-overlay">
        <div id="appDrawer" class="bmd-layout-drawer bg-faded">
          <div class="container">
            <header>Hello</header>
            <p>
              This is a longer block of information text.
              Regardless of how long this block of text is,
              the drawer should extend all the way to the footer.
            </p>
          </div>
        </div>

        <main class="bmd-layout-content">
          <div class="container">
            <h1>
            Hello
            </h1>

                <button class="btn btn-primary btn-raised" data-toggle="drawer" data-target="#appDrawer">Show Info</button>

          </div>
        </main>
      </div>
    </div>


    <footer class="flex-column h-100">
      <p>Thank you for visiting!</p>
    </footer>
</div>

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

The image fails to display when using THREE.js and Panolens.js

Trying to create a 360-degree environment with informational buttons using THREE.js and Panolens.JS However, I'm unable to resolve why the image is not appearing. Continuously encountering the error: Uncaught ReferenceError: process is not defined. ...

Removing a jQuery class while simultaneously adding it to different elements

I am currently working on a webpage where I have a row of 6 images. The first image, when the page loads, undergoes transformations using CSS3 due to a specific class applied to it. When the user hovers over the other images in the line, the same class is ...

Sending information to the styles feature in Angular 2

Is there a way to transfer data from an Angular tag to the styles in the @Component? Take a look at my component: import { Component, Input } from '@angular/core'; @Component({ selector: 'icon', template: `<svg class="icon"> ...

display a div based on the user's choice

I am working with the following http://jsbin.com/useqa4/10 My query revolves around hovering over li elements in the submenu using the code snippet below: $(".submenuList li").hover(function () { $(".submenuCurrent").removeClass("submenuCurrent"); $( ...

Rotate image in Vue3 using @click

I have a dashboard with a refresh button that I want to rotate 360 degrees every time it is clicked. How can I achieve this rotation effect on the image with each click of the refresh button? Below is the code snippet I have been working on, but it only r ...

Three-color linear gradient SVG with a middle color expanding in width

I'm working with a linear gradient and here is the code: <svg width="120" height="240" > <linearGradient id="dsp" x1="0" x2="0" y1="0" y2="1"> <stop class="stop1" offset="0%"/> <stop class="stop2" offset="50%"/> ...

Utilizing flexbox to create spacing between elements and ensuring there are no margins on the parent

Discover a Codesandbox demo at: https://codesandbox.io/embed/silly-firefly-87cov A unique challenge awaits with this project - elements within the parent container are positioned dynamically using flexbox. But how can we apply margins selectively only bet ...

Trigger a function when clicking outside the element, similar to how a Bootstrap modal is closed

I have successfully created a popup box using angular in my project. It appears when I click on an icon and disappears when I click on the close button. However, I would like it to also close if someone clicks outside of the popup. Can anyone help me with ...

Tips for aligning an element vertically when it has a float using CSS or JavaScript

I am struggling with centering the image within the article list loop I created. The code snippet looks like this: <article class="article <?php if($i%2==0) { echo 'even'; } else { echo 'odd'; } ?>"> <section class ...

Ensuring a DIV remains fixed in place for a specific number of scrolls

I'm looking to create a 'Page section' that remains in place while scrolling for a specific distance and then smoothly transitions to the next section. I've attempted to implement this within the child theme without success... Any sugge ...

Trouble with the query waypoints extension in a simple demonstration

Can anyone help me figure out why the basic example from the waypoints plugin isn't working for me? Here's a link to the jsfiddle I created: http://jsfiddle.net/ZA8bd/2/ CSS .block1 { margin-top:30px; width: 400px; background: red; ...

Ways to eliminate flickering when dynamically updating iframe content

Currently, I am in the process of constructing an iframe slideshow that consists of 7 webpages named event1.html to event7.html. To implement the automatic changing of the iframe source every 1 second, I am utilizing setInterval. However, I am facing an is ...

Alignment of images at the center within a container div while maintaining a height of 100%

Apologies if this question has already been addressed - I have tried numerous methods to center images horizontally without success. This particular image just does not want to align in the center! For reference, here is the JSFiddle link HTML: (Please n ...

Ensuring texture consistency for scene backgrounds in three.js

I am facing an issue with adding a background to a scene using a PNG image of 2k resolution. The background appears correctly sized on PC, but on mobile devices, it looks disproportionated. Here is the code snippet I am using: var texture = THREE.ImageUti ...

What is the CSS method for altering the color of a slider's runnable track upon selection?

Seeking assistance in changing the slider track color upon selection. Struggling to achieve the desired outcome of altering the color as it slides. CSS: /* Custom Styles */ .text-size-slider { line-height: 100%; font-size: 14px; position: relative ...

Error in Compass Compilation when encountering Unicode Characters

After compiling with Compass, I noticed that if I don't include @charset "UTF-8"; in my root scss file, the output looks like this: @charset "IBM437"; Even though my CSS output still displays the correct Unicode characters, such as: content: "ĐĂN ...

Is the navigation taking priority over all other content and adapting responsively alongside it?

My current project involves a responsive navigation, which is functioning properly. However, I am facing an issue with the content not aligning correctly under the navigation bar. I am struggling to find a solution to this problem. If you would like to rev ...

Is there a way to ensure that the div is displayed on the same line?

Check out the jsfiddle link provided: http://jsfiddle.net/HE7yT/ I'm trying to align the Image, content, and Amount in the same line. How can I achieve this? The goal is to have "150" displayed on the same line as the picture. var HTML = $(' ...

Various methods for deactivating controls in a CSS class

Is there a way to disable all buttons within a specific class? I have attempted the following code without success: $("input.myClass").attr('disabled', true); This is how I am trying to implement it: <script type="text/javascript> ...

Issue with CSS File not being recognized by React Component

After using the webpack create-react-app with npx, I encountered an issue with my component styling. Despite having a CSS file named header.css in the src directory alongside Header.js, my component does not seem to be styled correctly. Here is how my comp ...