Achieve scroll functionality in bootstrap modal

In my application, I am utilizing a bootstrap modal feature that contains lengthy content. Interestingly, I have encountered an issue with two different modals on separate pages. While viewing the modals on mobile devices, I noticed that one of them can be scrolled smoothly, whereas the other modal does not allow scrolling. Oddly enough, when attempting to scroll the second modal, it seems like the background is scrolling instead. It almost appears as if the second modal is not in focus, despite both modals having identical code structures:

 <div class="modal fade" id="modalFeedback" data-keyboard="false"  tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
   <div class="modal-dialog modal-lg modal-dialog-centered" role="document"> 

This unexpected behavior has left me puzzled, as I cannot pinpoint the reason behind it.

Answer №1

Give this code a try, it functions correctly:

<!DOCTYPE html>
<html lang="en>
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
</head>
<body>
<br><br><br>
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModalScrollable">
  Launch demo modal
</button>

<!-- Modal -->
<div class="modal fade" id="exampleModalScrollable" tabindex="-1" role="dialog" aria-labelledby="exampleModalScrollableTitle" aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalScrollableTitle">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>Cras mattis consectetur purus sit amet fermentum. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Morbi leo risus, porta ac consectetur ac, vestibulum at eros.</p>
       <p>Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.</p>
       <p>Aenean lacinia bibendum nulla sed consectetur. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Donec sed odio dui. Donec ullamcorper nulla non metus auctor fringilla.</p>
       <p>Cras mattis consectetur purus sit amet fermentum. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Morbi leo risus, porta ac consectetur ac, vestibulum at eros.</p>
       <p>Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.</p>
       <p>Aenean lacinia bibendum nulla sed consectetur. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Donec sed odio dui. Donec ullamcorper nulla non metus auctor fringilla.</p>
       <p>Cras mattis consectetur purus sit amet fermentum. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Morbi leo risus, porta ac consectetur ac, vestibulum at eros.</p>
       <p>Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.</p>
       <p>Aenean lacinia bibendum nulla sed consectetur. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Donec sed odio dui. Donec ullamcorper nulla non metus auctor fringilla.</p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>

</body>
</html>

I believe the above code will be beneficial to you.

Appreciate your time.

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

Trouble with AJAX/Live Search functionality

My files are ready for examination: The PHP File for Backend Search Functionality: <?php require "../sinfo.php"; function chk_phone($orig) { return preg_replace("/[^0-9]/","",$orig); } $s = $_POST["s"]; $sql = "SELECT * FROM requests WHERE id LI ...

Solving the "page not found" issue in NuxtJS: A guide to fixing errors during programmatic redirects

I am currently in the process of converting a Vue project into Nuxt. I have successfully implemented a navigation guard in the app using router.beforeEach(). Upon accessing the base URL localhost:3000, I encounter the image below: https://i.sstatic.net/ ...

Enabling LinkButton in Asp.net after a delay of 10 seconds: A Step-by-

After clicking on the LinkButton lbUpVoteUndo, I need it to be disabled for a set period of time, such as 10 seconds. I attempted to achieve this using c# code-behind but now I'm curious if there is an alternative method to accomplish the same task. ...

How can I generate a list of JavaScript files to be included in a template for both production and development environments using Grunt?

I need a way to organize a list of JavaScript files in one central location, either within gruntfile.js or an external JSON file, and then dynamically implement it into a template for both development and production environments. List of JavaScript files: ...

What is the process for configuring an HttpPost and specifying a header in JavaScript?

Every time I search for this question, I seem to find answers on how to set a header WITH JavaScript, but what I really want is to set the HttpPost Header FOR JavaScript. I am trying to log into a website, but I'm being told that I need to enable Jav ...

What is the best way to assign classes to the appropriate element based on the counter value?

Is there a way to add a class to the element that corresponds to a counter in jQuery? I currently have this code: var li_counter = 0; $("#trigger_heritage").click(function () { if(heritage_position >= heritage_versatz*13){ li_co ...

Dealing with jQuery AJAX and managing PHP session problems

Hopefully someone can help me with this issue. I have a registration page where entering a license code triggers a jQuery ajax success function that loads content from another page with an appended URL including a session ID: success: function(data) { ...

Selecting IMG src from XML Node with JQuery

Is it possible to extract the image src for each image from an RSS feed node that contains HTML? We are trying to display Google RSS feed stories, where we can access descriptions/links easily, but having trouble accessing individual images. Any help wou ...

Having trouble with implementing $off and passing parameters with eventbus in Vue

Creating an eventBus in main.js: Vue.prototype.$eventHub = new Vue() In component1: this.$eventHub.$emit('logged-in') Attempting to use the event in component2: beforeMount () { this.$eventHub.$on('logged-in', function () { ...

What is the best way to show the character count for every input in an Angular application?

In my app component, I have two input fields. I want to display the character count and max character limit for each input field dynamically as users type or blur on the input field. To achieve this, I created a component that shows and hides the characte ...

The fields in the row of the Rails form_tag are overly spacious

My login form in Rails 4 with Bootstrap 3 is giving me trouble. It doesn't format well on any device, especially smaller screens where it becomes unusable. I suspect the huge right margin of the rows is to blame, but I can't figure out the root c ...

Issue with color display inconsistency in webgrid across various segments

https://i.sstatic.net/UW17M.png My goal is to display section status colors in a webgrid and divide them percentage-wise, but I am facing issues with some of the rows. Here is the cshtml script for the webgrid section status: webGrid.Column(header: "Sec ...

Mobile view causes malfunction in Bootstrap Toggle Burger Menu functionality

<nav class="navbar navbar-expand-lg navbar-dark px-2 " style="background-color:#E53935;"> <a class="navbar-brand" href="#">FoodFusion</a> <button class=&quo ...

What is the best way to achieve this effect with CSS?

Is there a way to create this design with CSS? I experimented with applying border CSS and rotating the DIV, but couldn't quite achieve the desired result. Here is an image for reference: https://i.stack.imgur.com/yW6wK.png ...

Symfony2: Choice field string values not linked to form entity

One key feature of my application is a form that includes three dropdown lists for making choices. The first dropdown list is connected to a "relational" field in the entity and functions properly. Users are required to select a table link first from this ...

What is the best way to convert a repetitive string into a reusable function?

I am currently retrieving data from an API and I want to display it on my website in a more user-friendly manner. The challenge I'm facing is that the number of variables I need is constantly changing, along with their corresponding values. So, I&apos ...

Issue: This error occurs when attempting to double click on the diagram or a node but the show function for c is not recognized

I've encountered an issue with my gojs diagram. When I double click on it to edit the node name, I receive an error message. This problem occurred after upgrading my gojs version from v1.7.14 to v2.2.17. Below is the error stack trace: core.mjs:8453 E ...

What's the best method for creating a wraparound drop shadow effect in CSS without relying too heavily on hacks or workarounds?

I am seeking to create a rectangular DIV with drop shadows on all four sides. Some suggested solutions involve using negative and positive values for drop shadows or nesting multiple DIVs with different border colors. However, these methods seem makeshif ...

Is it possible to programmatically alter the clipboard using Javascript without requiring any user interaction?

I'm developing a script to simplify the reformatting of copied text, specifically phone numbers. I aim to paste the text into a textbox and have the formatted output automatically copied to my clipboard to reduce manual efforts. The function for upda ...

Creating custom Bootstrap Card Groups by dynamically generating the specified number of cards with Angular directives

I am currently using Angular 9.1.8 for my project. For my Angular component, I have implemented Bootstrap Card Groups and Cards to display a large result set of cards in rows with more than two cards per row. Below are four example cards: <div class=&q ...