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

Using a percentage width on a <div> element with the "overflow-x: scroll" property does not seem to be functioning properly, even when encapsulated within

My code includes a div within another div, taking up 50% of the page's width: <div id="mainContainer" class="mainContainer"> <div id="scroller" class="scrolling"> <!-- items here should make the div really long --> & ...

Using HTML to load an image is not possible, as it can only be done using CSS

I am currently dealing with a CSS issue in my project. Here is the code snippet from my stylesheet: .Img{ background: url('../assets/Trump.png'); } Now, let's take a look at the corresponding HTML code: <div class="Img"> However, ...

Begin the ul element from the left-hand side

Check out my latest JSFiddle creation: http://jsfiddle.net/alonshmiel/Ht6Ym/2409/ I'm attempting to align the ul element on the left side of the page: I've experimented with the following CSS rules: margin-left:0px; float: left; Unfortunatel ...

Creating personalized checkboxes

Trying to create custom checkboxes for different colors like red, blue, etc... https://i.sstatic.net/IKqJH.jpg Struggling to achieve the desired outcome Utilizing Bootstrap 5.3: Attempting to learn by dissecting a bootstrap template with the desired res ...

The performance of my Wordpress site is being hindered by the slowdown caused by Admin

I have a Wordpress website focused on winter sports vacations in Iceland: link Every plugin, WordPress core, and theme are up to date. Using Woocommerce for my online store. However, activating the Woocommerce plugin causes the site to slow down signific ...

Toggle the visibility of a div depending on the user's selection

My HTML select element has a few options to choose from: <select class="form-control" data-val="true" data-val-number="The field CodeSetup must be a number." id="CodeSetup" name="CodeSetup"> <option selected="selected" value="0">AllCodes< ...

How to customize the color of radio buttons in JFXRadioButton using CSS

I am facing an issue with customizing the styling of JFXRadioButton component from this library : jfoenix.com I want to modify the color of the circle, but the default class is not working. Are there any suggestions or solutions available? (The colors me ...

How can I use jQuery AJAX to generate a cookie or session?

In the process of developing my own JavaScript API for an online chat platform, I am looking to create a seamless experience for users by loading CSS and JavaScript files to generate a conversation window on their website. My goal is to make this API avail ...

What is the best way to include a dropdown menu in a navigation bar?

I am looking for guidance on adding a dropdown menu to my navbar in place of the "social media" section. Below is the code snippet I have been working with: <span class="navbar-toggler-icon"></span> </button> <div class="co ...

Simple method to modify the text size of the entire HTML page

Looking for a way to adjust the font size of an entire HTML document? I'd like to have two buttons - one to increase the font size and the other to decrease it. Each button will trigger a JavaScript function; function increaseFontSize(){ //Increase ...

Switch between attributes of two divs using jQuery

I am currently utilizing the hidden attribute to control the visibility of the .block div within each .item. However, my goal is to ensure only one block is visible at a time. How can I modify the code so that if one block is already visible and another i ...

The logo on my header is being covered by the menu due to the CSS code

Check out my website at bee-barcelona.herokuapp.com I'm facing an issue where the menu overlaps with the logo when I resize the browser or view the webpage on a tablet. I want to fix this using CSS. What changes do I need to make to ensure that the e ...

Is it possible to have an icon change color in a TableRow column when hovering over any part of that particular row?

I am currently using material-ui version 4.9.5. To illustrate my issue, I have created a simplified example here. I have a Table that is populated with basic JSON data. Each row in the table consists of an icon element along with its corresponding color a ...

What could be causing the issue of receiving the error message: "Uncaught TypeError: Cannot read property 'Title' of undefined"?

I am currently working on developing an AJAX web application. One of the functions I have is aimed at requesting a JSON object and then utilizing it to refresh the website content. Below is the portion of JavaScript causing an issue (Lines 8 - 16): windo ...

Using ckEditor alongside periodic jQuery Ajax for multiple editors is a powerful combination for enhancing text editing

Utilizing the inline edit feature of ckEditor along with Ajax from jQuery (learned from oleq) to showcase an issue that needs addressing. This set up functions smoothly when there is only one editor involved. The process involves reading text from a file ...

Firefox is not correctly rendering the embedded YouTube video within the iframe

Utilizing the amazing jQuery swiper plugin from , I crafted a dynamic scrolling player interface that showcases content "slide" by "slide", with each slide represented as an <article>. Certain slides need to display Youtube videos using the standard ...

Arranging buttons in a row with Bootstrap 5

Struggling to align the buttons on my webpage side by side in the center, I've tried two Bootstrap 5 classes but they're not achieving the desired look: https://gyazo.com/c23f2eade4614380aec547b11e61387a https://gyazo.com/e40a678b02c9f641f746b1c ...

Do not refresh the ajax content

I'm using Ajax to dynamically load HTML content into a div container. The content is loaded when an element with the class "link" is clicked, as shown below: $(".link").click(function () { $('.link').removeClass('current'); ...

Arrange the bootstrap columns in a grid layout both vertically and horizontally adjacent to one another

I need help with displaying my columns in this specific layout https://i.stack.imgur.com/2hzju.jpg Code <div class="row"> <div id="id-orders-stats" class="col-md-6 col-sm-6"> </div> <div class="col-md-6 col-sm-6 stats-box"&g ...

No data returned from Ajax request

I am using jQuery serialize and Ajax to capture form values and process them with JSON as the data type, but I am not getting any values returned. I have tried different approaches to troubleshoot this issue, but so far I haven't been successful. Ther ...