Tips for implementing a fully responsive left-side menu using Twitter Bootstrap 4.2

I'm attempting to design a layout featuring a top navbar and a collapsible left menu.

On medium-sized screens or smaller, the left menu should remain hidden. However, it needs to occupy the full height of the page at all times, regardless of its actual size.

Below is the code I currently have:

<div class="container-fluid h-100 mh-100 no-gutters pl-0">
  <div class="d-flex h-100">

    <div class="bg-dark h-100 mh-100 d-none d-md-block" style="min-width: 18rem; max-width: 22rem;">

      <ul class="list-group p-2">
        <li class="list-group-item">
          <a href="#" type="button" data-toggle="collapse" data-target="#multiCollapseExample2" aria-expanded="false" aria-controls="multiCollapseExample2">Parent - Test</a>


            <ul class="list-group collapse" id="multiCollapseExample2">
              <li class="list-group-item">Test</li>
              <li class="list-group-item">Test</li>
              <li class="list-group-item">Test</li>
            </ul>

          </li>
      </ul>
    </div>

    <main role="main" class="flex-grow-1 pl-3 h-100 mh-100">
      Here is main content....
    </main>

  </div>
</div>

Here is a fiddle link showcasing my code https://jsfiddle.net/7fcahme8/

Upon rendering the page, you'll notice that the left menu occupies 100% height. However, when clicking on "Parent - Test" on the left, the menu overflows the div which needs fixing. I want the left divider to expand as its content expands.

How can I ensure the left menu expands 100% of the time, regardless of its content?

I'm aiming to extend the left menu divider for expansion purposes. In the screenshot linked below, you can see that the list-group grows more than the menu: https://i.sstatic.net/bBxhj.png

Answer №1

In order to accomplish this, you must eliminate the h-100 classes. By doing so, the containers will be fixed at 100% of the viewport height. As a result, the overflow will wrap below and trigger the behavior you are currently observing.

If you establish a minimum height, it will occupy the space and grow as necessary. Below is a sample:

html, body {
      height: 100%;
      min-height: 100%;
    }

    .side-panel{
      min-height: calc(100vh - 56px); /* 100% view height - 56px (navbar height) */
    }
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js" integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script>

<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
  <a class="navbar-brand" href="#">Navbar</a>
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>
  <div class="collapse navbar-collapse" id="navbarNavAltMarkup">
    <div class="navbar-nav">
      <a class="nav-item nav-link active" href="#">Home <span class="sr-only">(current)</span></a>
      <a class="nav-item nav-link" href="#">Features</a>
      <a class="nav-item nav-link" href="#">Pricing</a>
      <a class="nav-item nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
    </div>
  </div>
</nav>


<div class="container-fluid no-gutters pl-0">
  <div class="d-flex">

    <div class="bg-dark d-none d-md-block side-panel" style="min-width: 18rem; max-width: 22rem;">

      <ul class="list-group p-2">
        <li class="list-group-item">
          <a href="#" type="button" data-toggle="collapse" data-target="#multiCollapseExample2" aria-expanded="false" aria-controls="multiCollapseExample2">Parent - Test</a>

            <ul class="list-group collapse" id="multiCollapseExample2">
              <li class="list-group-item">Test</li>
              <li class="list-group-item">Test</li>
              ... <!-- Additional list items truncated for brevity -->
            </ul>

          </li>
      </ul>
    </div>

    <main role="main" class="flex-grow-1 pl-3 h-100">
      Here is the main content....
    </main>

  </div>
</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

Different ways to showcase multiple columns in a bootstrap dropdown

In my React JS application, I successfully implemented a bootstrap dropdown control (located below Tag) that meets my needs. However, I am now seeking guidance on how to display multiple columns in the dropdown menu. Specifically, I would like to show bo ...

Achieving full-width container on mobile devices with Bootstrap

Despite my efforts in the CSS file, I am still struggling to get the container to take up the full width on mobile devices. Here is my CSS code: @media (max-device-width: 1024px) { .col-sm-2{ width: 100%; } .container { margin: 0 auto; width: ...

The margin 0 auto feature is ineffective, and instead, the target is activated upon the page's initial loading

As a beginner in CSS, I am encountering some issues with the HTML page of my application. I am currently working on an app and aiming to create a login view where the login form appears either after a voice command or button click. I am facing two main pro ...

Any ideas on how to present data in a card layout with two columns?

.card { box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2); transition: 0.3s; } .card:hover { box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2); } .container { padding: 2px 16px; } .card { width: 50%; heig ...

How to position a Bootstrap 4 button group at the bottom of a flexbox container

I am working with HTML code that looks like this: <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/> <div class="border d-flex align-items-baseline m-2 p-2" style="width: 400px"> < ...

URL for CSS Background-Image

While working on CSS styling for the body, I ran into a problem and was curious to understand the distinction. Initially, I tried this body { background-image: url('img/bg.png'); } However, it did not produce the desired result. http://www ...

Is there a way to easily align the text of the links in the bootstrap navbar to the center when it collapses?

I'm having trouble centering the links in the dropdown menu. Here is the code snippet: <nav class="navbar navbar navbar-expand-lg fixed-top bg clean-navbar"> <div class="container logo" style="position: relative;"> <a clas ...

How can I create a fixed sidebar that remains underneath the navbar using Bootstrap 4?

I am currently working on a website that features a Bootstrap 4 navbar at the top, with the class "sticky-top". This navbar does not have a fixed height. Below the navbar, there is a container-fluid div containing a sidebar on the left and a main content d ...

What is the best way to toggle between CSS rules on the left and right using jQuery?

I've incorporated a CSS class by using the following code: .dropdown-menu{right:0;} However, now I want to change the CSS property on the client side to: .dropdown-menu{left:0;} ...

Flipping the Script: Unraveling Bootstrap 4's Reverse Pull

Why isn't pull-right or pull-left working, and what am I doing wrong? The code in question <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh ...

Angular 4 allows the addition of an image from right to left upon clicking

I've been working on angular 4 and I've successfully implemented the functionality of adding flags. However, the issue is that the flags are currently appearing from left to right. What I'm aiming for is to have the images appear from right ...

When the screen size is extra small, utilizing the .container class in the navbar causes it

According to the documentation for bootstrap v4-alpha, it is possible to incorporate .container within the navbar in order to have content that is centered and non-fluid. However, there seems to be a problem with this feature on extra small displays, as th ...

Tips for vertically centering elements in the header using flexbox

Within the header of my website, I have structured 3 separate divs - one for a logo, one for a search input, and one for a cart link. My goal is to align these 3 .col-md-4 divs in a vertically centered position. While these divs currently have an align-it ...

drag and drop feature paired with additional textarea below

query 1: How can I make the bottom-left textarea move together with the top-left textarea when I drag it down? query 2: What is the solution to prevent the left-bottom textarea from moving when I drag down the top-right textarea? http://jsfiddle.net/4BX6 ...

Trouble aligning text next to boxes in Bootstrap Modal

Having trouble aligning the input text boxes in a modal form created with Bootstrap? The fields are currently showing under the labels instead of beside them. Looking for suggestions on how to fix this alignment issue. <button type="button" class= ...

How to style an unordered list to appear horizontally on Internet Explorer versions 6 and 7 using CSS

After creating a template for WebSVN, I put in the effort to ensure it adheres to web standards and validates. Most browsers display it well, but unfortunately IE 6 and IE 7 fail to render the unordered list horizontally. This causes each <li> elemen ...

If a CSS Selector is present, the following nested elements will be affected

I am looking for something similar to .class[height!="0"] .span Every time I attempt to nest something like div.item.class[height="0"] it doesn't seem to work. Can anyone provide assistance? :) Here is additional code: HTML <div class="barW ...

Trying to update the +/- icon on an accordion dropdown, however, the local HTML file is not loading the JavaScript file. (Using Bootstrap 4)

I'm completely new to JS and struggling a bit, so please be patient. I've been searching online for a few days now without much luck. I'm using Bootstrap 4 and trying to create an accordion with a +/- icon that changes when expanded or colla ...

Despite using "border-box" for the box-sizing property, the table cells are

Padding needs to be added to the cells of a table, but this is causing overflow issues with text and inputs inside the table. Despite attempting to set box-sizing: border-box, the problem persists. An example below demonstrates the issue: * { box-siz ...

Tips on restricting access based on User Browser type and version

I have a question regarding: My web application is built using PHP, AJAX, Javascript, CSS, and other technologies that may not be fully compatible with older browsers. Certain functions and styles might not work correctly on outdated browser versions. Th ...