The absolute div with 100% height fails to conceal the entire body of the scrollable modal

I am having trouble with a scrollable bootstrap modal that I want to cover with a white-transparent absolute div. I have set the modal body to a relative position and the absolute div to 100% height with top/bottom set to 0, but when scrolling, the absolute div doesn't cover the entire body.

.modal-body {
    position: relative;
    height: auto;
}

#loading {
    background: rgba(255, 255, 255, 0.5);
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    border: 1px solid red;
}
<!doctype html>
<html lang="en">

<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap/dist/css/bootstrap.min.css"
        integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N" crossorigin="anonymous">

    <link rel="stylesheet" href="./style.css">

    <title>Bootstrap Modal</title>
</head>

<body>
    <!-- Button trigger modal -->
    <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#staticBackdrop">
        Launch static backdrop modal
    </button>

    <!-- Modal -->
    <div class="modal fade" id="staticBackdrop" data-backdrop="static" data-keyboard="false" tabindex="-1"
        aria-labelledby="staticBackdropLabel" aria-hidden="true">
        <div class="modal-dialog modal-dialog-scrollable">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="staticBackdropLabel">Modal title</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <p>
                        Content goes here.
                    </p>
                    <div id="loading"></div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                    <button type="button" class="btn btn-primary">Understood</button>
                </div>
            </div>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/jquery/dist/jquery.slim.min.js"
        integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj"
        crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap/dist/js/bootstrap.bundle.min.js"
        integrity="sha384-Fy6S3B9q64WdZWQUiU+q4/2Lc9npb8tCaSX9FK7E8HnRr0Jz8D6OP9dO5Vg3Q9ct"
        crossorigin="anonymous"></script>
</body>

</html>

Answer №1

If you're fine with making some changes to the HTML structure, you might be able to resolve this issue by:

  1. Including a new parent div (.modal-body-wrap)
  2. Moving the #loader div outside of the .modal-body (scrolling) div
  3. Making slight adjustments to the styles as shown below

Updated HTML markup:

<div class="modal-header">
  ...
</div>
<div class="modal-body-wrap">
    <div id="loading"></div>
    <div class="modal-body">
        <p>
           Lorem ips...

Update the styles to:

.modal-body {
    height: 100%;
}

.modal-body-wrap {
    position: relative;
    max-height:75vh;
}

#loading {
    background: rgba(255, 255, 255, 0.5);
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    z-index:1;
    pointer-events: none;
}

This solution relies on support for pointer-events, which is widely supported: https://developer.mozilla.org/en-US/docs/Web/CSS/pointer-events

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

When the update button is clicked, the textfield is hidden; it reappears upon refreshing the page

Our marketplace multi-vendor site on Magento allows sellers to list their products for sale. The frontend displays the price using the following code: Phtml <input onFocus="showPriceCancel('<?php echo $products->getId(); ?>');" clas ...

CSS: Is it possible to make a div even smaller than the invisible padding of a font?

link to code: http://jsfiddle.net/xVCrn/1/ (best viewed in chrome / webkit) I'm attempting to create a 1px margin for the red section within the dark button area, but I am struggling to adjust the height of the red part. =( The objective is to: ...

What's the best way to center and expand a Bootstrap 5.3 dropdown menu to fill the entire width of the page?

I want to recreate the dropdown menu seen on this page, with the full width of the page but without any content. Additionally, I need all the "lorem" links in the menu to be centrally aligned in the navbar. Unfortunately, I am unable to modify the bootstra ...

Tips for dynamically inserting a new column into a table at any position other than the beginning or end

I have created a dynamic table where rows and columns can be added dynamically. However, I am facing an issue where I am unable to add a new column between the first and last column of the table. Currently, new columns are only being added at the end. $ ...

Adjust the height of a div using jQuery once the AJAX call retrieves the data

There is a div that always matches the height of the adjacent div, depending on the content loaded in it. This setup was functioning properly until I implemented a search feature using jQuery. Now, when I perform a search, the element used in the jQuery ca ...

Tips for tackling drag and drop functionality with only HTML, CSS, and JavaScript

Currently, I am faced with a challenge involving drag and drop TEST. Observing the image provided below, you will notice 3 columns each containing 3 small boxes of varying colors. These boxes are draggable, meaning they can be moved between columns follow ...

What is the best way to access the onclick calling object?

Is there a way to have a handler on the calling object of the onclick event? <a href="123.com" onclick="click123(event);">link</a> <script> function click123(event) { //I need access to <a> in order to man ...

Utilize a function with Document Write to output content onto a textarea

I am trying to implement a function that will display the result in a textarea using Javascript. Currently, the function writes the output on the body using document.write. However, I want the function to be triggered by an onclick button and display the ...

One way to display a div's inner HTML as its background is to apply a CSS rule

Help needed! <div class="container">red</div> <div class="container">green</div> <div class="container">#eeeeee</div> I am trying to dynamically set background colors for multiple divs based on their inner HTML co ...

Issue with the text wrapping of Angular mat-list-option items

When the text of my checkboxes is too long, it doesn't wrap properly. Please see the image below for reference: Click here to view Checkbox image and check the red box Here is my HTML code: <mat-selection-list #rolesSelection ...

Removing inline elements from a Bootstrap dropdown can be achieved by customizing the dropdown

I have a query regarding the use of dropdowns in Bootstrap. When I inspect the element after applying dropdown bootstrap, I notice that some properties are added inline: position: absolute; inset: auto auto 0px 0px; margin: 0px; transform: translate(0px, - ...

Only keep the href and target attributes (if target is not empty) in all anchor tags while removing all other attributes

My task involves manipulating an HTML string by removing all attributes from anchor tags, except for href and target (if target has a valid value). $content = '<p style="abc" rel="blah blah"> Hello I am p </p> <a href="https://example. ...

Removing nested divs using JavaScript

My website has a nested div structure which contains multiple child divs. Here is an example of the div structure: <div id="outside-one"> <div class="inside" id="1"></div> <div class="inside" id="2"></div> <div ...

The network tab is failing to display the CSS styles being applied to the selectors

Being new to markup languages, I encountered an issue when trying to apply my first CSS file to my index.html. Here is how I included the link tag in the HTML file for the CSS file: index.html code Upon checking the network tab in developer tools, I notic ...

Display or conceal the nearest element that was clicked

http://jsfiddle.net/KevinOrin/xycCx/1/ jQuery('.happening-main-text .readmore').click(function() { jQuery('.divmore').toggle('slow'); return false; }); ...

What could be causing my jQuery to not function on a separate domain?

Two of my websites have the same code, but one is functioning correctly while the other seems to be having trouble with the jQuery functions <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html;char ...

"Positioned at the top of the page is the alert box, with the

I'm looking to add an alert at the top of my webpage containing a form for visitors to enter their phone number. Currently, I have a "alert alert-info" div with the form inside it placed at the top of my body tag, which works perfectly. However, when ...

Ways to adjust the distance between logo and slider

I am using this script to showcase some products. You can find the script at: http://tympanus.net/Tutorials/ItemSlider/ When resizing the web browser from maximum size to smaller, I find that the height between the logo and shoes is too large for my likin ...

Challenges encountered while attempting to animate the CSS clip feature in WebKit

I've been searching everywhere for a solution to my issue, but none of them seem to work. As someone new to CSS3 Animations, I appreciate your patience. I created a simple animation using CSS3 that functions perfectly in IE and Firefox, however, it ...

What Is The Process for Logging Into an ASPX Site with Jsoup?

I've been attempting to access an aspx site using a Jsoup crawler for login purposes, but all the examples I've found involve forms. However, this particular aspx website here does not seem to have any forms available. How should I proceed with t ...