Prevent scrolling in a full-screen modal using CSS

I came across a beautiful fullscreen modal that is purely based on CSS. The only issue I encountered was that the modal isn't scrollable. I attempted various solutions but haven't been successful. Here's the script I am using:

Answer №1

Here's a captivating code example for you to dive into:

$(function () {
  $(".modal").hide();
  $(".modal-launch").click(function () {
    $("body").addClass("modal-open");
    $(".modal").fadeIn();
    return false;
  });
  $(".close").click(function () {
    $(".modal").fadeOut(function () {
      $("body").removeClass("modal-open");
    });
    return false;
  });
});
* {margin: 0; padding: 0; list-style: none; box-sizing: border-box;}

.modal {position: fixed; background-color: rgba(0,0,0,0.5); width: 100%; height: 100%;}
.modal .window {position: absolute; width: 70%; left: 15%; top: 15%; height: 70%; background-color: #fff;}
.modal .window .close {position: absolute; background-color: #f00; border: 2px solid #fff; border-radius: 100%; width: 32px; height: 32px; text-align: center; line-height: 20px; text-decoration: none; font-size: 1.5em; font-weight: bold; color: #fff; top: -16px; z-index: 3; right: -16px;}
.modal .window .wrap {overflow: auto; position: absolute; height: 100%;}

.modal-open {overflow: hidden;}
<script src="https://code.jquery.com/jquery-1.9.1.js"></script>
<div class="modal">
  <div class="window">
    <a href="" class="close">&times;</a>
    <div class="wrap">
      <h2>Microsoft</h2>
      <p>-------------------------------------------- </p>
      <p>------------------------------------------------------</p>
      <p>-------------------------------------------------------------------------------------------------------------</p>
      <p>-------------------------------------------------------------------------------------------------------</p>


    </div>
</div>
</p>
    </div></answer1>
<exanswer1><div class="answer accepted" i="33136833" l="3.0" c="1444851479" m="1444864646" v="2" a="UHJhdmVlbiBLdW1hciBQdXJ1c2hvdGhhbWFu" ai="462627">
<p>Take a look at this interesting piece of information:</p>

<p><div>
<div>
<pre class="lang-js"><code>$(function () {
  $(".modal").hide();
  $(".modal-launch").click(function () {
    $("body").addClass("modal-open");
    $(".modal").fadeIn();
    return false;
  });
  $(".close").click(function () {
    $(".modal").fadeOut(function () {
      $("body").removeClass("modal-open");
    });
    return false;
  });
});
* {margin: 0; padding: 0; list-style: none; box-sizing: border-box;}

.modal {position: fixed; background-color: rgba(0,0,0,0.5); width: 100%; height: 100%;}
.modal .window {position: absolute; width: 70%; left: 15%; top: 15%; height: 70%; background-color: #fff;}
.modal .window .close {position: absolute; background-color: #f00; border: 2px solid #fff; border-radius: 100%; width: 32px; height: 32px; text-align: center; line-height: 20px; text-decoration: none; font-size: 1.5em; font-weight: bold; color: #007;}4; top: -16px; z-index: 3; right: -16px;}
.modal .window .wrap {overflow: auto; position: absolute; height: 100%;}

.modal-open {overflow: hidden;}
<script src="https://code.jquery.com/jquery-1.9.1.js"></script>
<div class="modal">
  <div class="window">
    <a href="" class="close">&times;</a>
    <div class="wrap">
      <h2>Microsoft</h2>
      <p>----------------------------------------------------------------------------------------</p>
      <p>-------------------------------------------------------------------------</p>
      
    </div>
  </div>
</div>
<a href="#" class="modal-launch">Explore</a>

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

creating a table with only two td's for formatting

My ultimate goal is to keep my web form code as minimal as possible for easier maintenance. I am currently working on creating a questionnaire and have been using two td elements for this purpose. Here is an example of what the current text structure looks ...

Struggling with proper vertical alignment using Flexbox and achieving center alignment

I've been using JavaScript for displaying dynamic text and images, but I'm facing some formatting issues. Currently, I'm utilizing display: flex to position the text and image next to each other, but I'm struggling with horizontal alig ...

Animate the downward movement of the parent of a specific element, while simultaneously animating the upward motion of all others that are

When clicking a button, I am trying to slide down only the ul elements that are parents of the li.newlist element, while sliding up all the others. Although I have successfully managed to slide down the desired elements, I am unsure how to define the secon ...

Incorrect placement of navigation in HTML/CSS dimensions

I'm working on my new portfolio and I've run into an issue with the navigation placement that I can't seem to solve. The text should be aligned with the lines on the sides, but instead it's shifted right and down. I'm struggling t ...

Leverage the calc() function within the makeStyles method

const useStyles = makeStyles((theme) => ({ dialog: { '& .MuiTextField-root': { margin: theme.spacing(1), } }, address: { width:"calc(24vw + 8px)" }, })); <div> <TextField id="contact ...

Managing the Response from Google Geocode API in a Vue JS Component

I am facing an interesting challenge. I have a scenario where users can choose between two options - using their current location or entering a zip code. When a user inputs a zip code, I need to make a call to the Google geocode API to retrieve the central ...

Update in slide height to make slider responsive

My project involves a list with text and images for each item: <div class="slider"> <ul> <li> <div class="txt"><p>First slogan</p></div> <div class="img"><img src="http://placehold.it/80 ...

What is the process of utilizing jQuery to hover over a relevant cell?

I'm interested in learning how to implement jQuery to highlight related tables. Initially, I explored this JS fiddle and discovered a method for highlighting both vertically and horizontally. I conducted several searches to find a similar approach, ...

Tips for adjusting content that is 900px wide to fit properly on a mobile screen while maintaining its original width

https://i.stack.imgur.com/JELN5.png Despite trying various meta tag variations, I am struggling to get this image properly scaled and displayed in React.js. Any suggestions on how to resolve this issue would be greatly appreciated. ...

Searching for the precise draggable grid line position in rulerguides.js - tips and tricks!

Currently, I am utilizing rulerguides.js in my project. I have customized it for a specific div to display rulers and grid lines. You can refer to this FIDDLE. The rulers are functioning properly, but the draggable grid lines are being calculated based on ...

Conceal one object when the other is revealed?

Is there a way to hide the element with the class .close-button while showing another element with the ID #loading-animation? Can jQuery conditionals help achieve this? For example: if ($('#loading-animation').is(':visible')) { $ ...

Tips for automatically displaying the scroll bar continuously on iOS 15 without requiring user interaction

We have a Web Application that displays a scroll bar for users to navigate through the content. The scroll bar functions correctly on desktop browsers and Android browsers, but not on Apple devices running iOS 15 (Safari Browser). Current Behavior : In ...

How can I make angular material data table cells expand to the full width of content that is set to nowrap?

This example demonstrates how the mat-cells are styled with a specific width: .mat-cell { white-space: nowrap; min-width: 150rem; } If the width is not specified, the table will cut off the text due to the white-space property being set to nowrap. Is ...

Enhance the clarity of content within an IFrame by sharpening the focus on

I recently developed an iframe to open a chat site I built using React.js and Tailwind. The iframe is loaded dynamically on the website through javascript. However, I noticed that when I click on the input field inside the iframe, the content appears blurr ...

blurred image effect on bootstrap card hover

My attempt to create a blurred image effect on a bootstrap card hover is not working as expected. The blur effect works fine without the hover. Here is the code I have been using: .card-img { transition: all 1s ease; -webkit-filter: blur(0px); ...

Designing a webpage layout with DIV elements that span across multiple rows

I am attempting to create a layout that features two columns, with the right column spanning two rows. I am looking to accomplish this using only DIV tags: +-----------+-----------+ + + + + + + +-----------+ ...

Aligning a series of images with individual captions in the center

I am currently working on centering a row made up of four images along with their respective captions underneath. The code I am using is as follows: <div class="clear" style="text-align: center;"> <div style="float: left; padding-right: 10px;"& ...

Is there a way to log and process div data posted using jQuery in CSS format?

I am looking to extract and log a JavaScript-calculated result from an anonymous survey created using a WordPress plugin. The generated HTML code is: <div ref="fieldname57_1" class="cff-summary-item"> <span class="summary-field-title cff-summary ...

Is there a way in Material UI to dynamically update the border color of a TextField once the user inputs text?

Is there a way to style the border of a TextField only when it has text input? I am currently using the outlined version of the TextField, which displays placeholder text when empty. <TextField variant="outlined" /> So far, I have managed ...

Is there a way to display data in a checkbox field using PHP and JQuery Mobile?

I am currently working on a challenge in viewsessions.php. My goal is to retrieve multiple values from a database and group them into checkbox fields (such as typeofactivity, employer, date, time, amount as one combined checkbox field) using <input type ...