Steps to create a persistent bottom modal with scrollable content

I'm currently using Bootstrap 4.6 within my Angular application. I have implemented a modal that expands to full-screen on mobile devices, and now I want to add a fixed footer with scrolling body content.

I've attempted to adjust the height of the modal-content to 100% and set margins in the footer based on the height of the container, but unfortunately, I haven't been able to achieve the desired effect of having the content scroll behind the footer...

Here is an image depicting the current layout:

https://i.sstatic.net/1qR8z.png

The section displaying "Quantità" and other related components represents the footer. Here's the code snippet for my modal:

.modal-body {
  padding: 0;
}

.modal-footer {
  padding: 0;
  margin-bottom: 1.5rem;
}

@media (max-width: 767.98px) {
  .modal-footer {
    position: absolute;
    bottom: 0;
  }
}

@mixin modal-fullscreen() {
  padding: 0 !important; // override inline padding-right added from js

  .modal-dialog {
    width: 100%;
    max-width: none;
    height: 100%;
    margin: 0;
  }

  .modal-content {
    height: 100%;
    border: 0;
    border-radius: 0;
  }

  .modal-body {
    overflow-y: auto;
  }
}

@each $breakpoint in map-keys($grid-breakpoints) {
  $infix: breakpoint-infix($breakpoint, $grid-breakpoints);
  @include media-breakpoint-down($breakpoint) {
    .modal-fullscreen#{$infix} {
      @include modal-fullscreen();
    }

    .btn#{$infix}-block {
      display: block;
      width: 100%;
    }
  }
}
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="31535e5e45424543504171041f001f00">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-F3w7mX95PdgyTmZZMECAngseQB83DfGTowi0iMjiWaeVhAn4FJkqJByhZMI3AhiU" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="21434e4e55525553405161140f100f10">[email protected]</a>/dist/js/bootstrap.bundle.min.js" integrity="sha384-/bQdsTh/da6pkI1MST/rWKFNjaCP5gBSY4sEBT38Q/9RBh9AH40zEOg7Hlq2THRZ" crossorigin="anonymous"></script>
<ngb-modal-window role="dialog" tabindex="-1" aria-modal="true" class="d-block fade modal modal-fullscreen-sm show">
  <div role="document" class="modal-dialog">
    <div class="modal-content">
      <app-modal-product-content _nghost-cio-c135="">
        <div _ngcontent-cio-c135="" class="modal-header">
          <div _ngcontent-cio-c135="">
            <h4 _ngcontent-cio-c135="" class="modal-title text-truncate">CAFFE</h4>
          </div><button _ngcontent-cio-c135="" type="button" aria-label="Close" class="close"><span _ngcontent-cio-c135="" aria-hidden="true">×</span></button></div>
        <div _ngcontent-cio-c135="" class="modal-body">
          <ngb-accordion _ngcontent-cio-c135="" role="tablist" class="accordion" ng-reflect-close-other-panels="true" ng-reflect-destroy-on-hide="false" ng-reflect-active-ids="panel-aggiunte" aria-multiselectable="false">
            <!--container-->
            <div class="card ng-star-inserted">
              <div role="tab" class="card-header" id="panel-aggiunte-header"><button _ngcontent-cio-c135="" type="button" ngbpaneltoggle="" class="accordion-toggle ng-star-inserted" ng-reflect-ngb-panel-toggle="" aria-expanded="true" aria-controls="panel-aggiunte"><div _ngcontent-cio-c135="" ngbpaneltoggle="" class="aggiunte-title"><strong _ngcontent-cio-c135="" class="d-block mb-2">AGGIUNTE</strong><label _ngcontent-cio-c135="" class="d-block mb-0">Aggiungi ingredienti alla tua pietanza</label></div></button>
                <!--bindings={
  "ng-reflect-ng-template-outlet-context": "[object Object]"
}-->
              </div>
              ...

Answer №1

To create a modal with a fixed height for the body and scrollable content, follow these steps:

Example:

.modal{ height: 100vh; width: 100%;}
.modal-header{ height: 20vh;}
.modal-footer{ height: 20vh;}
.modal-body{ height: 60vh; overflow-y: auto}

This code assigns 100vh to the modal's height, where 20vh is allocated to both the header and footer, leaving 60vh for the body content. This configuration ensures that the body content can be scrolled if it exceeds the height of the modal. It also results in sticky headers and footers.

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

Is the renderer.setSize in Three.js calculated as a percentage of the screen size?

Is it possible to calculate the renderer.setSize based on a percentage of the screen? For instance, could I set my frame to be 80% of the device width and 80% of the device height? ...

Tips on changing the URL of the current tab after clicking on a link

const selenium = require('selenium-webdriver'); require('chromedriver'); const By = selenium.By; const driver = new selenium.Builder().forBrowser('chrome').build(); const url = 'https://example.com'; driver.get(url) ...

storing data in a nested child object within an array

I am attempting to include variables into the existing JSON data that is received from an API whenever a user clicks on the add button. However, I encountered this error message: Cannot find a differ supporting object '[object Object]' of type & ...

In order to make Angular function properly, it is crucial that I include app.get("*", [...]); in my server.js file

Recently, I delved into server side JavaScript and embarked on my inaugural project using it. The project entails a command and control server for my own cloud server, operating with angular, Expressjs, and bootstrap. Presently, I am encountering challeng ...

In the n-th click event, the key press button is fired n times

I am working on developing a game that includes a start button. Once this button is clicked, the game will begin and involves various keyboard key press events. The issue arises when the start button is clicked multiple times causing the game to run repeat ...

Is it possible to customize the pagination-control labels from numbers (1 2 3) to different values, such as 'Anything1 Anything2 ...', by utilizing ngFor* with an array in ngx-pagination?

Is there a way to customize ngx-pagination's pagination control? Currently, the page numbers are displayed as '1 2 3' but I would like to replace them with specific string values from an array. <pagination-controls (pageChange)=& ...

Using Angular $scope in web workers

What is the best way to access angular $scope data in Web Workers? I'm currently experimenting with using parallel.js library for this purpose. $scope.variant = 7; $scope.final = 0; var p = new Parallel([0, 1, 2, 3, 4, 5, 6]), log = function () { co ...

Guidance on creating a custom color selection tool for a specific task

Looking for assistance in converting a code snippet that uses <button> elements to select colors into a color picker. I am unsure how to retrieve the selected color and use it within a JavaScript function. Can someone provide guidance on this? Here i ...

Prohibit entry to JS and CSS files

I am looking to restrict access to js and css files. If a user attempts to access a file with the extensions .js or .css, I want the website to redirect them to a 404 page. The code provided below is not functioning as intended. It is blocking all web pag ...

AngularJS $resource sends the id as a query parameter rather than including it in the URL

I'm trying to retrieve data from a rest API by using the product id as part of the URL, rather than as a query parameter. Here is the factory code: .factory('Products', ['$resource', function($resource) { return $reso ...

Utilizing a checkbox within a select dropdown component in Vue

Has anyone come across a checkbox dropdown feature in Vue? I have been searching online but couldn't find any examples or resources related to this. If someone has a working skeleton for it, please share! ...

Transferring scope between pages without the need for an angular service definition

Looking to open a new JSP page while passing the $scope in order to utilize an array response generated in the initial page. Example from test.js file: (function() { 'use strict'; angular .module('test', []) .control ...

Can babel 7 deconstruct imports, is it feasible?

Is there a workaround in Babel 7 for exporting modules and deconstructing them using the previous syntax? I'm having trouble achieving the following: // file1.js export const x = 0; export const y = 1; export default z; // file2.js import { x, y } f ...

After the CSS3 transformation, a click event does not follow

Encountering an issue with Chrome/Safari browsers. Following the application of CSS3 transformation, the mouseup and click events are not being triggered (though they work fine in IE9/10). Here is an example of the non-functional code: <script type="t ...

Ways to retrieve parameters in getStaticPaths function?

I'm currently working on a Next.js app with Contentful as the CMS. The file structure relevant to my question is: pages -[category] -[slug].js My goal is to access the category value when a user visits category/slug. Currently, I have the category ...

Plugin refresh after callback

I have a webpage that features a row of buttons at the top, followed by some content below. Whenever one of the buttons is clicked, the content is updated using UpdatePanels. Within this content, I am attempting to incorporate the royal slider plugin, wh ...

React: Using useState and useEffect to dynamically gather a real-time collection of 10 items

When I type a keystroke, I want to retrieve 10 usernames. Currently, I only get a username back if it exactly matches a username in the jsonplaceholder list. For example, if I type "Karia", nothing shows up until I type "Karianne". What I'm looking f ...

The inability to access a route with an authentication guard in the app controller is causing the validate function in the local strategy file to not run

While trying to access my login route in the app.controller.ts of my rest api built with Nestjs and Prisma, I encountered a 401 error response. I have been closely following the official documentation provided by Nestjs on authentication (https://docs.nest ...

Switching between VR/StereoEffect modes in Three.js

The initial scene is functioning well in VR mode, but the challenge lies in switching back to normal mode. var scene = new THREE.Scene() var camera = new THREE.PerspectiveCamera( 75, window.innerWidth/window.innerHeight, 0.1, 1000 ) camera.position.set(70 ...

ReactJs not responding to rotation feature

System: Operating System: Windows 7 - 64 bit I am attempting to manipulate the rotation of a div in Reactjs by using click and drag mouse events similar to this example written in javascript code, which works flawlessly. I created a ReactJs applicatio ...