What steps can I take to ensure that the upper and left sections of a modal dialog remain accessible even when the size is reduced to the point of overflow?

One issue I'm facing is with a fixed-size modal dialog where part of the content gets cut off and becomes inaccessible when the window shrinks to cause an overflow. More specifically, when the window is narrowed horizontally, the left side is cut off and can't be accessed. And if it's shortened vertically, the top portion is also cut off and not reachable even with scrolling.

At the bottom, I will provide a fiddle with a simple example demonstrating this problem. The modal service uses its own HTML and CSS similar to the fiddle, with classes prefixed by ".modal-". The modal has a fixed size that covers the entire screen, and inside it, there's a body div meant to wrap the dialog received from elsewhere, which can have various sizes (typically fixed as shown in the example, but can vary since different dialogs are used). The class representing the passed-in dialog is ".dialog-container". Is there any solution to address these issues without disrupting the current functionality or assuming a specific size for the dialog being passed in? I've been stuck on this for some time now. Here's the fiddle link: https://jsfiddle.net/zrb42vex/

<div class="modal">
<div class="modal-body">
    <div class="dialog-container">
      Top
    </div>
</div>
</div>
<div class="modal-background"></div>

        .modal {
      position: fixed;
      top: 0;
      right: 0;
      bottom: 0;
      left: 0;
      z-index: 1000;
      overflow: auto;
    }
    
    .modal-body {
        position: absolute;
        height: fit-content;
        width: fit-content;
        background: #fff;
        border-radius: 5px;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
    }
    
    .modal-background {
      position: fixed;
      top: 0;
      right: 0;
      bottom: 0;
      left: 0;

      background-color: #000;
      opacity: 0.75;
    
      z-index: 900;
    }
    
    .dialog-container {
        height: 500px;
        width: 600px;
        padding: 20px;
    }

Snippet:

.modal {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 1000;
  overflow: auto;
}

.modal-body {
  position: absolute;
  height: fit-content;
  width: fit-content;
  background: #fff;
  border-radius: 5px;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.modal-background {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background-color: #000;
  opacity: 0.75;
  z-index: 900;
}

.dialog-container {
  height: 500px;
  width: 600px;
  padding: 20px;
}
<div class="modal">
  <div class="modal-body">
    <div class="dialog-container">
      Top
    </div>
  </div>
</div>
<div class="modal-background"></div>

Answer №1

Seems like the concept you're explaining is flex. I've added some borders and a pink background just to demonstrate, along with some additional content to showcase where it "resided". I played around with making part of the content flex as well.

EDIT: Updated to specify a fixed size for .dialog-container

.modal {
  position: fixed;
  display: flex;
  align-items: center;
  justify-content: center;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 1000;
  overflow: auto;
  border: solid 1px red;
}

.modal-body {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  border-radius: 5px;
  border: solid 2px lime;
}

.modal-background {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background-color: #ffdddd;
  opacity: 0.75;
  z-index: 900;
}

.dialog-container {
  width: 300px;
  height: 250px;
  display: flex;
  flex-direction: column;
  /* stack them */
  align-items: center;
  padding: 20px;
  border: solid 3px blue;
}

.home-run {
  justify-self: flex-start;
  width: 15rem;
  height: 4rem;
  border: 1px solid #ddffdd;
  background-color: #ddddff;
  /* align the text in the middle of the div */
  display: flex;
  align-items: center;
  justify-content: center;
}
<div class="modal">
  <div class="modal-body">
    <div class="dialog-container">
      Top of the morning to you! I have more fun stuff similar to this span: <span>I am a span</span>
      <div class="home-run">I am a div doing div things</div>
    </div>
  </div>
</div>
<div class="modal-background"></div>

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

Display JSON data in a table format using Angular

I have received a JSON result that looks like this: { "discipline":"ACLS", "course": [ { "value":"ACLS Initial", "classes":"0", "students":"0" }, { "BLS":"CPR Inst ...

I'm looking to use JavaScript to dynamically generate multiple tabs based on the selected option in a dropdown menu

I'm reaching out with this question because my search for a clear answer or method has come up empty. Here's what I need help with: I've set up a dropdown titled 'Number of Chassis'. Depending on the selection made in this dropdown ...

You may only insert a single image into a container

My goal is to display two images side by side with text centered between them. However, when I add the first image using CSS and the background property, I run into issues adding a second image as it overrides the first one. Placing the images directly in ...

I am unable to display the content even after setting `display: block` using the `.show()`

Hello there, I have attached my javascript and html code. While in debug mode, I can see that the CSS property 'display: none' changes to 'display: block', but for some reason, the popupEventForm does not open up. Any suggestions on why ...

Determine the total number of active links on an HTML webpage using F#

Currently, I am working on developing a basic F# function that will be able to count the total number of links present in a given HTML website URL. I understand that this can potentially be achieved by counting the occurrences of the "<a" substrings, b ...

Tips for overlaying text on the background in Next.js:

I'm currently working on creating an image element with overlay text. Check out my jsx code below: <div className={styles.img}> <img src={src} alt="" /> <p>{`(${size})`}</p> </div> And here is t ...

What steps can be taken to provide accurate information in the absence of ImageData?

Utilizing a JS library to convert a raster image into a vector, I encountered an issue where the library returned a fill of solid color instead of the desired outcome. I suspect that the problem lies within the ArrayBuffer. The process of loading an imag ...

ng-repeat is not functioning properly despite the presence of data

Currently, I am in the process of building a basic Website using the MEAN stack, but I'm facing an issue with an ng-repeat that is failing to display any content. Oddly enough, when I attempt something similar in another project, it works perfectly fi ...

Blending PHP with jQuery

I'm currently working on the same page as before but this time, I'm using it to experiment with jQuery. I'm trying to learn it for my 'boss', but unfortunately, I can't seem to get the JavaScript in this file to run at all, le ...

What is the best way to customize the color scheme of a Bootstrap 4 range slider?

https://i.sstatic.net/MBona.png Looking for suggestions on how to customize the colors of ranges in Bootstrap 4 and change the blue thumb color to 'gray'. Below is the example HTML input code: <p id="slider" class="range-field"> <in ...

Issue with JQuery causing maxlength input not to work

Is there a way to use JQuery to set the maxlength attribute for an input[type='text'] while users are typing, so that once the max value is reached, input will stop? This is the code I have been trying: $(document).ready(function(){ $(&apos ...

Challenges with Loading JSON Dynamically in Next.js using an NPM Package

In my TypeScript project, I have implemented a functionality where a json configuration file is dynamically loaded based on an enum value passed as a parameter to the getInstance function in my PlatformConfigurationFactory file. public static async getIn ...

Using React with Typescript: Passing Props and Defining Data Types

As a relatively new TypeScript enthusiast, I find myself facing some challenges. Specifically, I am struggling with errors in my code and uncertain about how to properly pass props and select the correct type. Any guidance on this matter would be greatly a ...

Tips for eliminating horizontal scrolling in a fixed width layout

When designing a responsive website using media queries, I encountered an issue where the screen size changes to 320px and all elements are also set to 320px, but a horizontal scroll appears. Despite my efforts, I am unsure how to resolve this problem. ...

Exploring methods to iterate through an extracted div using Selenium in Python

In my previous step, I encountered a challenge while trying to extract text from a div. After several hours of troubleshooting, I was finally able to achieve the desired result. However, the next step proved to be equally difficult as I needed to implement ...

Wordpress isn't loading CSS as expected (I believe...)

Recently, a wordpress based website I am working on suddenly stopped pulling the CSS files...or at least that's what it seems like. I can't post a screenshot of the wordpress admin dashboard because I don't own the site and my boss might no ...

Multiple columns contained within a span

I'm trying to create a panel that displays a list of values with corresponding labels. The requirement is for each label to be positioned above its respective value and aligned to the left. The layout should resemble the following: Label 1 Lab ...

How can HTML be utilized to create a brief description?

I want to insert a link into the brief description that says "Read More..." which will direct the buyer to the main description further down on the product page when clicked. Can someone please provide guidance on how to achieve this? The URL for the link ...

Attempting to trigger the timer to begin counting down upon accessing the webpage

Take a look at this example I put together in a fiddle: https://jsfiddle.net/r5yj99bs/1/ I'm aiming to kickstart as soon as the page loads, while still providing the option to pause/resume. Is there a way to show the remaining time as '5 minute ...

How to create a vibrant and colourful full background

How can I make the background color fill the entire width of the page? I am new to HTML and CSS, so below is the code I have used for setting the background. Please provide clear instructions on what changes I need to make in my code to achieve this. I kno ...