Fullscreen vertical div with centered content and scrollbar

I want to create a full-screen, vertically centered div that overlays all content below it.

/* css */
#overlay {
    background: #fff;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow-y: auto;
}

/* Applies to the <body> tag */
.overlay-hidden {
    overflow: hidden;
}

<!-- html -->
<body class="overlay-hidden">
    <div id="overlay">
        <!-- Content of overlay goes here -->
    </div>
    <div class="container">
        <!-- Main content goes here -->
    </div>
</body>

Check out my code here: https://jsfiddle.net/uzy78s69/. It works well, but when I add more content to #overlay, it doesn't behave as expected: https://jsfiddle.net/uzy78s69/1/

Click on the X or Create new post link to see how it behaves.

What am I doing wrong? How can I fix this issue?

Answer №1

Simply insert

#box > .container {
  max-height: 100%;
}

Check out the example on JSfiddle: jsfiddle.net/uzy78s69/3

Answer №2

To fix the issue, simply delete the line display:flex; from the #box CSS class.

Demo

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

Alter the element's class during drag and drop操作

While in the process of dragging an element, I want to dynamically change its class or any CSS property based on its position. Here is what I have achieved so far: https://jsfiddle.net/twfegqgc/ The issue I am facing is that the class changes only when t ...

Avoid removing content when using bootstrap popover

My goal is to incorporate HTML within a Bootstrap 5 popover. I made some modifications to the code to extract HTML content from a specific div without using the data-bs-content attribute. The current code structure is as follows: $(document).ready(fu ...

"Implementing a right-aligned dropdown menu in the navbar using Bootstrap 4

I am encountering an issue with the dropdown menu in Bootstrap 4. Here is my code snippet: <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link href="https://stackpath.bootstrapcdn.com/font-awesom ...

How come my flexbox items are not aligning in a row when using v-for?

I have designed a component that acts as a container for multiple items, using v-for to display four of these containers on my page. However, they are currently only shown in a single column layout and I need them to be displayed in two columns per row on ...

How to Achieve This Effect Using Engine Limited's HTML and CSS - Step-by-Step Guide

As I continue to learn the art of article writing on wiki webpages, I have been exploring ways to replicate a certain effect that I found on another site using the same Gamepedia engine. I have spent days searching for solutions with no luck. Here is the ...

Issue with spacing dropdown choices within primary navigation bar

Struggling with my final project for a class as the semester comes to a close. I've received minimal help from my Professor and hit a roadblock. The main navigation on the side is working correctly, but the dropdown options are stacking on top of each ...

Are there any outstanding problems with jQuery's ajax function in Internet Explorer 8?

I recently implemented a jQuery .ajax() call to load feed-items into a ul, inspired by code I found on var timestamp = true; // determine if timestamp is displayed $.ajax({ type: "GET", url: "sample-feed.xml", ...

Sending intricate data structures to a Web Api using the HTTP method "GET"

Can anyone help me with passing a complex object to a web API? Here is the code I am using: Javascript: $("#btnFetch").live("click", function () { var dualdata = { Code: "XXX", Module: "1" }; $.ajax({ cache: false, url: fetchProfileUrl, type ...

What is the best way to add content within the same form group element?

I am attempting to display an auto-complete (suggestion) list in a textbox using jQuery and AJAX. Here is my HTML code: <div class="col-md-6"> <div class="form-group"> <label class="control-label">Depart Location</label&g ...

What is the recommended approach for passing parameters to a JavaScript function from an anchor tag?

I recently came across this intriguing question: What is the best practice for using Javascript and Anchor Tags? The suggestion provided in response to this query involves utilizing the following code snippet: <a id="foo" href="#">Click Me</a&g ...

Automatically conceal a div or flash message after a short period of time by utilizing CSS3 in a React

I am relatively new to the React environment and recently created a basic component for a bookmarking feature. Essentially, when the favourite icon is clicked, an ajax call is sent > a record is created in the database > on ajax success, a flash me ...

The horizontal display of images is currently experiencing issues

I am having trouble displaying images horizontally in a row. I am aiming to show 8 images next to each other, but my current grid system setup is not achieving this. The images are currently stacked on top of each other, but I want them to be aligned horiz ...

Creating PDF files with PDFkit in Node.js while rendering HTML data

I am looking for a way to generate a PDF file using the 'PDFkit' library. The data is being retrieved from a MySQL database, and some of the content includes HTML tags. However, when I try to render the HTML data to PDF using the 'html-to-te ...

Accessing HTML control in code-behind

Can someone explain to me how I can access attributes in the code behind that have been added to an HTML control using jQuery? Here is the ASP.NET control I am working with: <asp:TextBox ID="myID" CssClass="class1 class2 " runat="server"></asp: ...

unable to insert HTML image

In my current project, I am facing an issue with embedding a banner image into HTML emails that are sent out after a forum is filled out. Previously, the code worked fine when using the latest version of PHP, but due to server requirements, I had to downgr ...

Ways to navigate to a tabbed section that is currently inactive

One of my challenges involves managing a tabbed form with multiple tabs: <ul class="tab-links"> <li class="active"><a href="#tab1">Pending</a></li> <li><a href="#tab2">All</a></li> ...

Instructions for implementing the iPhone Contacts header scroll effect on an HTML webpage

If you take a look at this jsFiddle I've set up, it should give you a better idea of what I'm trying to accomplish: http://jsfiddle.net/nicekiwi/p7NaQ/2/ Imagine the contact page on an iPhone's iOS, where as you scroll through the alphabet ...

Create static HTML web pages using information from a text file

Exploring a new concept of a random joke generator that loads a unique html page with a quirky joke every time. Currently, the main index page is structured like this: <!DOCTYPE html> <html> <head><title>Jokes</title> ...

Using PHP code to dynamically update the CSS styles on a

I am looking to adjust the css based on section_name. For example, if the section is labeled Featured, the css should include right:0. On the other hand, if the section_name is Latest, the css should include left:0. Is there a way to incorporate some PHP c ...

Troubleshooting: Django update causing issues with CSS background image display

Recently, I made an upgrade to my Django 1.10 (Python 3.5) app to Django 1.11 (Python 3.6). Most of the functionalities are still intact, however, I am facing a peculiar issue where my CSS background images are no longer rendering (even though they work fi ...