The overflowing pop-up container

When I trigger a popup that dynamically generates a fixed background with a centered dialog, it works well. However, on smaller monitors like laptops, tablets, and phones, the content can overflow beyond the visible area due to its fixed container, making it inaccessible. This issue is most pronounced on smaller Android devices because when the form input in the popup is triggered, it causes the Android keypad to cut the screen real estate in half.

I have attempted several solutions, such as setting a maximum height on the dialog and setting overflow-y to scroll, but this cuts off the full popup on monitors where it fits correctly, negatively impacting the aesthetics.

Are there any simple solutions that I might be overlooking? I am open to implementing CSS or jQuery fixes.

JSfiddle:http://jsfiddle.net/L77v4caL/9/

Video of the problem: https://youtu.be/LW9EeMVarcM (unable to scroll to the bottom of the popup, it simply gets cut off.)

Full HTML:

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>test</title>
<link rel="stylesheet" type="text/css" href="css/styles.css"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script>
$( document ).ready(function() {
    /* If button is clicked create dialog */
    $('.button').click(function () {
        /* Create background */
        $('body').prepend('<div id="dialog-bg"></div>');
        /* Create popup & form */
        $('#dialog-bg').append('<div class="dialog"><h2>Popup banner</h2><div class="large-content">This could be a large form or an iFrame to a youtube video<form><input name="email" placeholder="Form example" required=""></form></div></div>').hide().fadeIn(500);
        /* Create close button */
        $('.dialog').prepend('<div class="close-dialog"><a class="close" href="/">x</a></div>');
        /* Remove default link behaviour from close button */
        $('a.close').click(function () {
            return false;
        });
        /* Close all on click */
        $('.close, .close-dialog').click(function () {
            $('#dialog-bg, .dialog, .close-dialog .close').remove();
        });
    });
});
</script>
<style>
#dialog-bg {
    top: 0;
    z-index: 1;
    width: 100%;
    height: 100%;
    position: fixed;
    background: url(https://dl.dropboxusercontent.com/u/12645552/overlay.png) 0 0 repeat;
}

.dialog {
    width: 350px;
    padding: 20px;
    position: relative;
    margin: 50px auto 0;
    background-color: #fff;
}

.large-content {
    color: #fff;
    height: 300px;
    padding: 20px;
    background-color: #000;
}

.close-dialog {
    z-index: 1;
    width: 28px;
    height: 28px;
    right: 15px;
    top: 15px;
    cursor: pointer;
    text-align: center;
    border-radius: 50%;
    position: absolute;
    background-color: #fff;
    -webkit-box-shadow: 0px 0px 0px 2px rgba(0, 0, 0, 0.6);
    -moz-box-shadow: 0px 0px 0px 2px rgba(0, 0, 0, 0.6);
    box-shadow: 0px 0px 0px 2px rgba(0, 0, 0, 0.6);
}

a.close {
    color: #000;
    font-size: 1.3em;
    line-height: 1.2;
    font-family: arial;
    text-decoration: none;
}

.button {
    color: #fff;
    padding: 10px;
    cursor: pointer;
    text-align: center;
    background-color: #2599ca;
}

.button:hover {
    text-decoration: underline;
}
</style>
</head>
<body>
<h1>Lorem ipsum</h1>

<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus eleifend felis at aliquet rhoncus. Nunc gravida in augue et rhoncus. Nam leo ex, pretium a neque eu, accumsan efficitur ligula. Mauris sodales nulla at orci pharetra vehicula. Vivamus quis odio at mi venenatis varius. Proin nec tristique odio. Donec dictum suscipit odio et rutrum. Quisque rutrum vestibulum diam, sit amet porttitor nulla volutpat ut. Fusce mattis enim eget pulvinar congue. Nunc euismod sapien ut blandit egestas. Integer in tempor est. In quis enim at quam ornare maximus ac eget mauris.</p>
<p>Maecenas quis mollis nulla. Suspendisse quis bibendum dolor, quis tempor elit. Morbi dolor ante, dignissim eu orci in, pretium sagittis massa. Nullam tincidunt tortor vel bibendum feugiat. Quisque a dolor nec ante imperdiet ullamcorper. Fusce ac risus congue, gravida ex sed, mattis erat. Suspendisse potenti. Aenean ullamcorper nisl eu interdum egestas. Donec a porta justo. Maecenas dapibus lacus non odio iaculis mollis. Integer a cursus magna. Vestibulum sollicitudin, urna nec consequat convallis, dui dolor lacinia enim, sit amet mattis diam nunc non justo. Aenean finibus, nisi vel feugiat venenatis, magna nisl lobortis massa, sed vestibulum tellus ex ac tellus. Etiam a risus facilisis, congue ex vel, pretium ipsum. Suspendisse eget sapien nisi. Sed rhoncus tortor ut velit volutpat feugiat.</p>
<p>Praesent consequat justo quis magna ultrices fringilla. Nam ullamcorper sit amet massa nec finibus. Sed enim neque, dictum ullamcorper accumsan a, fringilla quis turpis. Nam et consequat tellus. In nibh lectus, malesuada congue tortor sed, aliquam fringilla enim. Sed euismod nisi et lectus rhoncus, nec pharetra tortor pulvinar. Cras pretium ullamcorper lorem nec fringilla.</p>
<p>Mauris venenatis sem nibh, in fringilla enim tempus quis. Nullam et tellus pretium, dictum nunc vel, venenatis ipsum. Pellentesque congue libero ac lobortis maximus. Nam tincidunt euismod facilisis. Cras volutpat, augue vitae consectetur tempor, libero augue placerat nunc, eu placerat ex lacus nec nulla. Pellentesque nisl nisi, tempus ac scelerisque in, vestibulum in libero. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.</p>
<p>Nam elementum lectus est, id porttitor magna tempor id. Ut metus orci, sagittis sagittis venenatis sit amet, pulvinar eu eros. Suspendisse sed gravida purus. In tincidunt urna elit. Maecenas at malesuada nisl. Donec ut congue risus. Etiam volutpat efficitur facilisis. Donec tellus nibh, sodales vel gravida ut, ullamcorper quis sapien. Aliquam erat volutpat. Donec ultrices mauris at pulvinar tempus. Donec pretium, lectus vel laoreet feugiat, felis sapien dapibus augue, at pellentesque diam lorem dapibus ipsum. Nulla sit amet mattis ante, sit amet vestibulum nisi.</p>
<div class="button">Click me</div>
</body>
</html>

Answer №1

Give this a shot, include overflow-y within #dialog-bg and make adjustments in .dialog

#dialog-bg{
    overflow-y:scroll;
    top: 0;
    z-index: 1;
    width: 100%;
    height: 100%;
    position: fixed;
    background: url(https://dl.dropboxusercontent.com/u/12645552/overlay.png) 0 0 repeat;
}

    .dialog {
        width: 350px;
        padding: 20px;
        background-color: #fff;
        position: absolute;
        margin: auto;
        top:0;
        bottom:0;
        left:0;
        right:0;
    }

Answer №2

Include this code snippet to enable scroll functionality within the popup window. Feel free to customize the appearance to suit your content, and experiment with adjusting the height of the content area.

.popup-container{overflow:auto;}

Answer №3

Many thanks to everyone for their valuable comments that helped me put together a functional solution: http://jsfiddle.net/L77v4caL/14/

One observation is that I need to manually assign a maximum height to each popup, but other than that, everything seems to be working fine.

 <!doctype html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>test</title>
    <link rel="stylesheet" type="text/css" href="css/styles.css"/>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
    <script>
    $( document ).ready(function() {
        /* If button is clicked create dialog */
        $('.button').click(function () {
            /* Create background */
            $('body').prepend('<div id="dialog-bg"></div>');
            /* Create popup & form */
            $('#dialog-bg').append('<div class="dialog"><h2>Popup banner</h2><div class="large-content">This could be a large form or an iFrame to a youtube video<form><input name="email" placeholder="Form example" required=""></form></div></div>').hide().fadeIn(500);
            /* Create close button */
            $('.dialog').prepend('<div class="close-dialog"><a class="close" href="/">x</a></div>');
            /* Remove default link behaviour from close button */
            $('a.close').click(function () {
                return false;
            });
            /* Close all on click */
            $('.close, .close-dialog').click(function () {
                $('#dialog-bg, .dialog, .close-dialog .close').remove();
            });
        });
    });
    </script>
    <style>
    #dialog-bg {
    overflow-y:scroll;
    top: 0;
    z-index: 1;
    width: 100%;
    height: 100%;
    position: fixed;
    background: url(https://dl.dropboxusercontent.com/u/12645552/overlay.png) 0 0 repeat;
}

.dialog {
    background-color: #fff;
    bottom: 0;
    height: 80%;
    max-height: 450px;
    left: 0;
    margin: auto;
    overflow: auto;
    padding: 20px;
    position: absolute;
    right: 0;
    top: 0;
    width: 80%;
}

.large-content {
    color: #fff;
    height: 300px;
    padding: 20px;
    background-color: #000;
}

.close-dialog {
    z-index: 1;
    width: 28px;
    height: 28px;
    right: 15px;
    top: 15px;
    cursor: pointer;
    text-align: center;
    border-radius: 50%;
    position: absolute;
    background-color: #fff;
    -webkit-box-shadow: 0px 0px 0px 2px rgba(0, 0, 0, 0.6);
    -moz-box-shadow: 0px 0px 0px 2px rgba(0, 0, 0, 0.6);
    box-shadow: 0px 0px 0px 2px rgba(0, 0, 0, 0.6);
}

a.close {
    color: #000;
    font-size: 1.3em;
    line-height: 1.2;
    font-family: arial;
    text-decoration: none;
}

.button {
    color: #fff;
    padding: 10px;
    cursor: pointer;
    text-align: center;
    background-color: #2599ca;
}

.button:hover {
    text-decoration: underline;
}
    </style>
    </head>
    <body>
    <h1>Lorem ipsum</h1>

    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus eleifend felis at aliquet rhoncus. Nunc gravida in augue et rhoncus. Nam leo ex, pretium a neque eu, accumsan efficitur ligula. Mauris sodales nulla at orci pharetra vehicula. Vivamus quis odio at mi venenatis varius. Proin nec tristique odio. Donec dictum suscipit odio et rutrum. Quisque rutrum vestibulum diam, sit amet porttitor nulla volutpat ut. Fusce mattis enim eget pulvinar congue. Nunc euismod sapien ut blandit egestas. Integer in tempor est. In quis enim at quam ornare maximus ac eget mauris.</p>
    <p>Maecenas quis mollis nulla. Suspendisse quis bibendum dolor, quis tempor elit. Morbi dolor ante, dignissim eu orci in, pretium sagittis massa. Nullam tincidunt tortor vel bibendum feugiat. Quisque a dolor nec ante imperdiet ullamcorper. Fusce ac risus congue, gravida ex sed, mattis erat. Suspendisse potenti. Aenean ullamcorper nisl eu interdum egestas. Donec a porta justo. Maecenas dapibus lacus non odio iaculis mollis. Integer a cursus magna. Vestibulum sollicitudin, urna nec consequat convallis, dui dolor lacinia enim, sit amet mattis diam nunc non justo. Aenean finibus, nisi vel feugiat venenatis, magna nisl lobortis massa, sed vestibulum tellus ex ac tellus. Etiam a risus facilisis, congue ex vel, pretium ipsum. Suspendisse eget sapien nisi. Sed rhoncus tortor ut velit volutpat feugiat.</p>
    <p>Praesent consequat justo quis magna ultrices fringilla. Nam ullamcorper sit amet massa nec finibus. Sed enim neque, dictum ullamcorper accumsan a, fringilla quis turpis. Nam et consequat tellus. In nibh lectus, malesuada congue tortor sed, aliquam fringilla enim. Sed euismod nisi et lectus rhoncus, nec pharetra tortor pulvinar. Cras pretium ullamcorper lorem nec fringilla.</p>
    <p>Mauris venenatis sem nibh, in fringilla enim tempus quis. Nullam et tellus pretium, dictum nunc vel, venenatis ipsum. Pellentesque congue libero ac lobortis maximus. Nam tincidunt euismod facilisis. Cras volutpat, augue vitae consectetur tempor, libero augue placerat nunc, eu placerat ex lacus nec nulla. Pellentesque nisl nisi, tempus ac scelerisque in, vestibulum in libero. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.</p>
    <p>Nam elementum lectus est, id porttitor magna tempor id. Ut metus orci, sagittis sagittis venenatis sit amet, pulvinar eu eros. Suspendisse sed gravida purus. In tincidunt urna elit. Maecenas at malesuada nisl. Donec ut congue risus. Etiam volutpat efficitur facilisis. Donec tellus nibh, sodales vel gravida ut, ullamcorper quis sapien. Aliquam erat volutpat. Donec ultrices mauris at pulvinar tempus. Donec pretium, lectus vel laoreet feugiat, felis sapien dapibus augue, at pellentesque diam lorem dapibus ipsum. Nulla sit amet mattis ante, sit amet vestibulum nisi.</p>
    <div class="button">Click me</div>
    </body>
    </html>

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

Sending an array of JSON objects using jQuery is a simple and straightforward process. By

I'm currently facing a challenge while working on my web page - I am struggling to send an Array of JSON objects to my PHP backend script. Below is the JavaScript code I have been using (with jQuery): var toSend = new Array(); ...

Switch between dropdowns with jQuery

Issue at Hand: In the scenario illustrated below, there is a side navigation bar containing options that reveal a toggled section upon clicking. Specifically, if you select the third item labeled "Dolar" from the menu, a dropdown with three additional cho ...

What's the reason behind the absence of applied bootstrap style in jsFiddle?

Link to the code: Click here I'm having trouble understanding why the default style of <ol> from Bootstrap is not being applied in this particular code. Any insights? Here's a snippet of the HTML code taken from the fiddle. <ul> ...

Unable to retrieve dropdown value using JavaScript and display it in a div

javaScript code: Retrieving data from a dropdown and displaying it in the inner HTML of a div. function showcost() { var days = document.getElementById("Ddays"); var Dudays = days.options[days.selectedIndex].text; var div = docu ...

Is there a way for me to stack the submenu links on top of each other?

Is there a way to rearrange the submenu links so they appear stacked vertically instead of horizontally? Currently, they line up next to each other under the main menu and subsequent links fall below the submenu. I believe it involves adjusting the positio ...

Perform an Ajax request to a C# Controller Function

In my javascript file named "data handling.js" within a folder labeled "JS", you'll find the following piece of code: document.getElementById('submit-new-project').addEventListener("click", function () { var ProjectName = document.getEl ...

Receive AJAX aid for PHP/MySQL dynamic dropdown menu implementation

My goal is to dynamically populate a second drop-down menu based on the selection made in the first drop-down. The first drop-down contains a list of tables from my database, and the second drop-down should display providers associated with the selected ta ...

Updating user credits through the Model::factory() method is a common practice in my workflow

I need to update the UserCredits after a purchase. For example, if a user currently has 10 credits and purchases 10 more, I want to add the purchased credits to their existing total. The goal is to increment the current credit score with the new credits ...

How come I am able to successfully send a Post request through Postman, but encountering issues when trying to do the same

I am facing an issue with my NodeJs/Express Webservice. When I send a POST request to the webservice using Postman, it works fine. However, when I try to send a POST request using JavaScript, I encounter the error {message: "Cannot read property 'path ...

Tips for creating a smooth transition using cubic bezier curves

In my current project, I have implemented a CSS transition using the cubic bezier timing function with values (0.16, 1, 0.29, 0.99). However, I have encountered an issue where at the end of the animation, the element's velocity is too slow and the in ...

Relative positioning can break the background-clip attribute for text elements

I am experimenting with using background-clip: text on an element that contains some child <p> elements. I wanted to enhance the design by adding some absolutely positioned :after elements to the <p> tags, covering up the text for animation eff ...

Hovering over an element will change its background color along with adjusting the background

I encountered a situation with the following code: CSS: <style> div.testy { border:1px solid black; } div.testy:hover { background-color:red; } </style> HTML: <div class="testy" style="height:100px; back ...

Connecting a string array to the navigation bar

Need Assistance with AngularJS: In my controller, I have a string array that looks like this: var app = angular.module('myApp', []); app.controller('mycontroller', function($scope) { $scope.menuitems =['Home','About&apos ...

Activate the file upload window when an option is chosen from the dropdown menu

Is there a way to automatically trigger the file input when "UploadStudents" is selected from the dropdown menu? Dropdown Menu <select name="performaction" id="performaction"> <option value="">- Actions -</option> <option value=" ...

Is it possible to conceal and completely empty the TextBox once the checkbox is deselected?

When the checkbox is checked, the textbox is displayed; otherwise, it remains hidden. However, the value is not being cleared. Can someone please help me with this issue? Thank you in advance. HTML <div class="munna"> <in ...

What is preventing the control from being passed back from the PHP file to the AJAX success function?

My website is built using PHP, Javascript, and AJAX. Below is the essential code snippet: JS code (AJAX function): $("#btn_add_event").click(function(){ var strSeriaze = $( "#formAddEvent" ).serialize(); url = $( "#formAddEvent" ).attr('act ...

Effective Methods for Implementing CSS Variables within nth-child Selectors

Objective: To pass a variable successfully as a parameter to nth-child. The task is to make the third line turn green in the example provided. Dilemma: Currently, the parameter is being disregarded as a variable. Inquiry: Is achieving this possible? If s ...

Transforming the appearance of the menu element in Vue using transitions

In my Vue app, I have this SCSS code that I'm using to create a smooth transition effect from the left for a menu when the isVisible property is set to true. However, I am encountering an issue where the transition defined does not apply and the menu ...

Verify whether the initial value is distinct from the subsequent one using AJAX

I'm currently working on a project where I need to compare the first value received from an AJAX call to the subsequent values. However, I seem to be stuck and unable to figure out how to achieve this. Every 5 seconds, I am checking the follower count ...

What is the best way to incorporate two foreach loops in Laravel within a single view?

<h2 class="section-subheading text-muted text-center">First Course</h2> <div class="row text-center"> @foreach ($data as $item) <div class="col-md-4 px-3"> <div cl ...