applying flexbox for overlay with overflow effect

During the checkout process, I implemented an overlay on top of the website that disables scrolling on the body but allows overflow on the overlay. However, the content on the overlay gets clipped if the viewport is too small. How can this issue be prevented? I attempted to solve it by adding overflow:auto to the overlay, but it was not effective:

body {
  overflow: hidden;
}

#overlay.active {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
  overflow: auto;
  background: yellow;
}
<div id="overlay" class="active">
  <div style="height:300px; background:white; padding:20px">
    content
  </div>
</div>

Answer №1

UPDATE

One possible solution to the issue is to include margin: auto on the child div containing the content:

#overlay > div { margin: auto; }

An alternative approach would be to use safe for the align-items property, although it currently only works in Firefox:

align-items: safe center;

Here is an example showcasing the implementation:

body {
  overflow: hidden;
}

/* 👇 Added on the child div */
#overlay > div {
  margin: auto;
}

#overlay.active {
  position: fixed;
  /* 👇 Can use shorthand (Optional: not supported by older browsers and IE) */
  inset: 0;
  display: flex;
  justify-content: center;
  /* 👇 Safe is only working on Firefox as of now  */
  align-items: safe center;
  padding: 20px;
  background: #fff;
  overflow: auto;
  background: pink;
}
<div id="overlay" class="active">
  <div style="height:300px; background:white; padding:20px">
    content
  </div>
</div>

Answer №2

For proper scrolling behavior, consider removing the align-items:center; property from #overlay.active. This adjustment allows the content to scroll as intended. Since #overlay.active contains only one child item, align-items (responsible for positioning flex items along the cross axis) has no visible impact.

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

What is causing the image to become distorted on the canvas?

Despite specifying the image dimensions to be 50px by 50px, it appears stretched on the y-axis like this. View Stretched Image I suspect that the issue lies with the CSS styling applied. Here is my current CSS code: canvas { background-color: green; ...

A variable in Javascript storing data about jQuery DOM elements

Currently, I am using the slick slider for my development (http://kenwheeler.github.io/slick/) In JavaScript, there is an event that returns a variable called 'slick' When I print the variable using console.log, this is what I see: https://i.s ...

Unicef's animated web content

Looking to learn more about gate animation and zoom page transition on the Unicef website? I want to incorporate these cool animations into my own project. Can someone provide me with a "keyword" or point me in the right direction to find information on ...

Close all other sections when one is expanded

I have been exploring the Bootstrap 4 Collapse feature and I'm trying to figure out how to automatically collapse other sections when one is expanded. Here's what I have tried so far: <p> <a class="btn btn-primary" data-togg ...

"Discover the step-by-step process for displaying the menu on a WordPress

After installing the new classifieds theme on my Wordpress website, I noticed that the menu from the previous theme is still showing up. However, when I hover over the menu, it disappears and only reappears once my cursor is no longer hovering over it. ...

Scrolling to specific ID scrolls only in a downward direction

I have been using fullpage.js for my website and I am facing an issue. When I create a link and connect it to an id, everything works perfectly. However, I am unable to scroll back up once I have scrolled down. Here is the HTML code: <a href="#section ...

"Client-side style not rendering correctly in Internet Explorer 8 when accessed through server in

I have noticed some strange behavior with my .net application. Everything appears fine when running it from Visual Studio on IE8: However, once I deploy the application to my server and access it via URL, it seems to lose its margin: It's puzzling t ...

Java Applet for capturing specific sections of a webpage to create a screenshot

Does anyone know of a way (applet or something else) to capture a screenshot of the content within a specific div on a webpage? I came across this Java code for capturing a screenshot of the entire screen: import java.awt.AWTException; import java.awt.Re ...

The Calendar Widget in jQuery UI

Can someone help me figure out how to change the maxDate based on the minDate plus one week in this code snippet? Currently, the maxDate is calculated from the current day, but I need it to be dynamic. Here's the code: $( function() { $("#dat ...

Retrieve the webpage content (including any iframes) using a Firefox plugin

Hello there! I am currently working on retrieving data from a webpage that is updated using Javascript. Initially, I attempted to create a Java program to periodically fetch this page from the server, but the information was being updated too slowly. The ...

Determine if a link can be activated or disabled

Controlling the clickability of a link and displaying an error based on the result of an ajax call is my current objective. <a class="lnkCustomer" href="http://localhost/viewcustomer" target="_blank" data-customerno="2 ...

Is there a way to collapse an element by clicking either the content inside the div or the button within the div?

Is there a way to make a button within a newly activated div close it? The existing code seems to have issues with this functionality, and adding new rules or functions has not solved the problem. Any assistance with fixing this issue using vanilla JavaScr ...

Placing the image at the bottom of the container

I need help positioning the image in the center of div: #two, with the screen of the laptop displayed in div two and the lower body of the laptop in div: #three. Here is an example image of how I want it to look, but I'm struggling to achieve this. ht ...

Making an Ajax request using the identical ID

My current approach involves utilizing an ajax call to achieve the following: Each time a link is clicked, it generates a new link at the bottom with the same text. HTML : <nav class="navbar"> <ul> <li> ...

Configuring Google Maps API (including charts) for maximum height of 100%

I am having trouble getting my map to display at 100% height using the Google Maps API. I've encountered similar issues in the past with the Google Charts API as well. From what I've gathered, it seems like setting the height of the html and bod ...

Navigate to the following input field upon a keyup event occurring within the table

I have a table that contains multiple input fields in a single row within a td element. I am trying to implement functionality that will automatically shift focus to the next input field when any number is entered. The code works perfectly without the tabl ...

Tips on displaying dynamic content on a single page with AngularJS 1.6

Just getting started with Angular and looking for a way to display dynamic content from a JSON file using AngularJS 1.6? Here's an example to help you out. News.json { "Articles": [ { "Title": "News 1", ...

What kinds of font file formats are you utilizing?

In numerous projects, I have observed a common practice of using multiple font extensions such as .TTF, .WOFF, and .WOFF2. However, this can result in having multiple files for a single source. Imagine the clutter if one has several sources with different ...

Does anyone know why this code isn't functioning properly on Firefox?

This code performs as intended in Chrome, but unfortunately does not function properly in Firefox. ul { list-style:none; } li { display:inline-block; border:1px solid black; } a { display:block; margin:10px; } a:hover { positio ...

Retrieving the text from the img tag of a bs4.element.Tag

I have a question that needs to be addressed. My concern involves a list of bs4.element.Tags, similar to the one illustrated in the image below. The issue at hand is filtering out only the href tags that are preceded by an <img> tag. How can this s ...