Empty square appears after adjusting window size on mobile devices

There is a container that has position:fixed and takes up the entire screen size:

.overlay {
        position: fixed;
        top: 0;
        left: 0;
        height: 100%;
        width: 100%;
        background: blue;
    }
    

The issue arises when scrolling down on mobile devices such as iPhones and Androids. As the address bar "shrinks" (i.e. window height increases), the height of .overlay remains constant, resulting in a blank space right below it until further scrolling.

An attempt was made to bind a window resize event in order to dynamically adjust the height of .overlay:

$(window).resize(function(){
        $('.overlay').css("height", "100%");
    });
    

However, this method did not have any effect. Any suggestions on how to solve this?

Answer №1

Give this a shot:

.overlay {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  background: blue;
}

Opt for flexbox rather than fixed positioning:

body {
  display: flex;
  min-height: 100vh;
}
.overlay {
   flex: 1 0 auto;
   width: 100%;
}

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 the best way to display my simple signup/login forms on the page without redirecting by using AJAX?

After spending some time looking at it, I've come up with a basic sign-up and log-in form that I want to display on the same page in a div, rather than redirecting to a new page. Here's the code snippet for my controller: class UsersController ...

Do not allow navigation to another page until the form has been submitted

As part of my project, I have implemented a feature where new users are required to change their password upon logging into their account for the first time. For new users, the Change Password screen is displayed immediately after login. The menu options ...

Arrow icon indicating active status in side navigation bar

As part of my journey to enhance my Html and Css skills, I have been recreating templates from various websites. While this exercise has taught me a lot, I have hit a roadblock with one particular template. I am struggling to understand how they manage to ...

Delete the float attribute from the image when the inline-block is shifted to the bottom of the image

I have three elements in my design - a title, a paragraph, and an image. I want the image to float to the right, with the title and paragraph floating to the left and bottom, resembling "Image 1." To prevent the title from wrapping when narrowing the oute ...

Show JSON data as choices in a dropdown menu

On my webpage, I want to display a dropdown list populated with objects from a JSON file using JavaScript. Here is the structure of my HTML and JSON: HTML <html> <body> <select id="myid">MyList</select> <script src="m ...

Validation of nested phone numbers using jQuery

I'm trying to figure out how to incorporate the jQuery validation plug-in into a multi-step form where validation occurs on each step as the user progresses. I know that typically, the validation plug-in is triggered by a submit request, but in this c ...

Creating a button that can automatically scroll to a specific table row

I have implemented code that fetches data from my database and displays it in a table format. The code snippet is shown below: <body> <?php include('navbar.php'); ?> <div class="container"> <h1 class="page-header text-ce ...

We're sorry, the page you are looking for cannot be found. Error 404: Page Not Found

Good day: I am encountering this Django error when attempting to update a "User": Page not found (404) Request Method: GET Request URL: http://127.0.0.1:8000/users/modify/ Using the URLconf defined in APPNAME.urls, Django attempted these URL pa ...

Attempting to change the src of a different image using jQuery upon clicking

I have two separate divs that change their background image source when clicked, which is working fine. However, I would like them to change the other image they are paired with. For example, if div 1 is clicked and becomes "open", then if div 2 is "open" ...

Is there a way to make a table stay at a specific width for screen sizes larger than 1000px, but then adjust its size accordingly as the window size decreases?

<table id="example" class="row-border compact" style="width:1000px; table-layout:fixed;"> The table is currently set to have a width of 1000px, but I would like it to be 90% of the screen width when the window size is less than 1000px. Is it possibl ...

What is the best way to showcase specific information from a JSON file with the help of

Our corporation is looking to showcase job listings that we promote on a prominent job platform. They provide us with JSON data so we can exhibit our company's job openings on our website. I aim to present essential information in a summary format, w ...

What causes jQuery to output individual characters instead of the entire content of the span element when looping through it?

I am facing an issue with a group of span elements that have the "endtime" class. My goal is to retrieve each of their contents separately from one another. <span class='endtime'> 2011-03-29 00:01:03 </span> <span class='e ...

How can I make a hidden element occupy space before using jQuery to fade it in on mouseover?

Looking for a way to have an element take up space even when hidden, then using jQuery mouseover to make it appear? Check out this example: http://jsfiddle.net/Nj97k/ When I set visibility to hidden, the icon no longer fades in on mouseover. ...

What is the process for applying negative filtering to data tables using jquery plugins?

Hey there! I'm currently working with the data tables plugin for jQuery and I'm trying to tweak my server-side script to allow for negative searches, like !foo. The idea is to show everything except for foo. I have some code that I've been w ...

Adjust the child element's value by referencing the parent class name

I need to update the content of child elements within an HTML file based on the class name of their parent element, using JavaScript. While I have successfully achieved this for static values by creating a TreeWalker for text nodes, doing the same for dyn ...

Tips for modifying the appearance of this input document

Hey there, I have this input element created in React: <span className="btn-file" type='button'> <div style={{display:'flex',justifyContent:'space-around'}}> <span style ...

Unlimited scrolling in Laravel for paginated results

As a newcomer to Laravel, I am currently working on a project utilizing Laravel version 4.2. My main challenge lies in implementing infinite scroll to load more results instead of relying on default pagination. Despite exploring various jQuery plugins and ...

How can you extract information from a text document and seamlessly incorporate it into an HTML webpage?

I am currently working with an HTML file structured like this.. <html> <body> <table border="1" cellpadding="5"> <tr> <td>Some Fixed text here</td> <td id="data">---here data as per values in external text file--- ...

Using the Google Picker API to dynamically load a file picker when needed

I am interested in integrating the Google Picker API. The provided example demonstrates the picker being loaded upon page load, but I would like the picker to load when a specific action is taken, such as clicking on a button. However, implementing this be ...

Using Ajax to access the API variable through its URL attribute

My main goal is to configure a User ID and API Key within the URL for an Ajax call: Currently, I am doing: $.ajax({ url: "https://www.googleapis.com/plus/v1/people/115332174513505898112?key=AIzaFrCzbKLawSPG8C0tjZDozO1bSWx49mJm13s", context: document. ...