Unexpected white space appears at the bottom of the page when rotating the device in iOS Safari

One issue I encountered on my website involves a meta tag:

<meta name="viewport" content="width=device-width, initial-scale=1.0">

This, combined with height:100%; on the html and body tags, causes problems when viewed on Safari (iOS 13.5.1). Specifically, when the device is rotated from landscape to portrait mode, a white space appears at the bottom of the screen that is not part of the HTML code.

A minimal example can be seen here: https://jsbin.com/cojabiquza

This issue seems to be related to Safari's behavior of hiding and showing panels during rotation, leading to a miscalculation of page dimensions. Removing the viewport meta tag resolves the problem, but this is not a viable solution for a responsive website like mine. The issue does not occur in other browsers.

If you have experience fixing this issue, please share your insights.

Answer №1

@Jax-p's solution initially addressed the bug I was facing, however, it ended up causing another issue. The use of 100vh resulted in the content getting hidden behind the address bar, as shown in this https://i.sstatic.net/7caUo.png.

Consequently, I had to implement a series of workarounds in my actual application:

document.addEventListener('orientationchange', () => {
  document.documentElement.style.height = `initial`;
  setTimeout(() => {
    document.documentElement.style.height = `100%`;
      setTimeout(() => {
        // This particular line prevents the content
        // from being obscured by the address bar
        window.scrollTo(0, 1);
      }, 500);
  }, 500);
});

This temporary fix more or less resolves the issue on iOS Safari versions 12 and 13.

Answer №2

After spending the majority of my day tackling this persistent "feature," I successfully devised a CSS-only solution that is compatible with iOS 14.4 on both iPad and iPhone, as well as all standard web browsers. What's more, no hacks are needed to implement it. The key lies in utilizing 100vh for the HTML and BODY elements, accompanied by applying position:fixed to the outermost wrapper element with its edges set to zero.

Please bear in mind that there may be a visual glitch when rotating the screen if the background color of your BODY differs from that of the wrapper. Interestingly, this same issue can be leveraged to customize the color of the address bar at the top by intentionally assigning a distinct background color to the BODY (though this step is optional).

HTML, BODY {
    height: 100%;
    width: 100%;
    height: 100vh;
    width: 100vw;
    margin:0;
    padding:0;
    /* essential for preventing unwanted scrollbars */
    overflow: hidden;
    /* aesthetic tweaks: */
    background-color:#5AE;
}
#wrapper {
    position:fixed;
    top:0;
    left:0;
    right:0;
    bottom:0;
    padding:0;
    margin:0;
  /* to enable normal content scrolling: */
  overflow: auto;
    /* aesthetic tweaks: */
    background-color:#AEA;
    border: #6B6 1em solid;
    box-sizing:border-box;
}
<html>
<head>
    <meta name="viewport" content="height=device-height, initial-scale=1, width=device-width, initial-scale=1" />
</head>
<body>
    <div id="wrapper">
        Insert your content here.
    </div>
</body>
</html>

Answer №3

When browsing on mobile devices, the address bar and controls menu are often hidden while scrolling or when switching between portrait and landscape mode. This can sometimes cause issues with using height: 100%; as the browser may not correctly recalculate percentage values (such as failing to account for the height of the address bar).

To ensure that your content fills 100% of the viewport height, it is recommended to use height: 100vh; (where vh stands for viewport height). Hopefully, this tip proves helpful for your development.

Answer №4

check out this solution:

<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">

Answer №5

In my quest to find a resolution to this issue, I stumbled upon this helpful blog post that provided the following solution:

window.onresize = function() {
    document.body.height = window.innerHeight;
}
window.onresize(); // calling this to initially set the height.

Answer №6

This solution was a game-changer for me, especially when using my iPhone 15

@media (max-width: 799px) {

  main {
    overflow-x: clip;
    overflow-y: auto;

    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 0;
    margin: 0;
  }
  
  }

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

There are two directories for pods in Xcode. How can I delete one of them?

Currently, I am working on a project that involves two identical pods directories. I am unsure if there are any drawbacks to this setup and how it came to be. Can someone guide me on how to remove one of the pod directories? https://i.sstatic.net/c3LFu.pn ...

CSS will only be visible if it is enclosed within the <style> tag

While creating a view, I noticed that my CSS is not being displayed unless it's placed inside a <style> tag. I've tried using !important without success, as well as utilizing the selector .container-fluid > .row > .d-flex > .out_pr ...

Removing page scrolling in Bootstrap 5: A step-by-step guide

I would like to ensure that only the card-body block is scrollable. Currently, the page does a bit of scrolling when the card-body block overflows (resulting in 2 scroll bars). The lorem text was added as an example of an overflow. The desired outcome is d ...

A guide on utilizing Python with Selenium to navigate to a specific field within a frame

I am seeking assistance in using Selenium with Python to target a specific element that seems to be located inside a frame. Specifically, I am attempting to select the element with 'id' = 'kiadvany_cim' within what appears to be a windo ...

Learn how to use the CSS transform-scale() function to scale text independently from its container while maintaining proper alignment

I am currently working on adjusting font sizes to match another one, but I am facing an issue where the container's size is also being affected, resulting in misalignments. I have experimented with different display types (block, inline) and even trie ...

Gridview displaying varying border styles in CSS

I'm really struggling with this issue. I have a GridView and I want to ensure that the borders are consistent across all browsers. Right now, I'm experiencing different outcomes in IE, FF, and Chrome. Despite my best efforts with CSS (I'm re ...

The negative z-index is causing issues with my ability to select classes using jQuery

By setting a z-index of -3 for several divs in my background, I thought they wouldn't affect the formatting of elements in the foreground. But now I'm facing an issue where I can't click on those background divs when trying to target them wi ...

Troubleshooting directive not functioning properly with AngularJS ng-click

My HTML img tag is not responding to ng-click when clicked. I'm puzzled by this issue occurring in masonryPictureView.html Main page - home.html <ng-masonry> <ng-picture ng-items="projectdescription.pictures"></ng-picture> </n ...

Including JavaScript in HTML Error 404

https://i.stack.imgur.com/aQDPG.png I am struggling to understand why this import is not functioning as expected. I have tried using script/import.js but it still fails to work. The error message I keep receiving is: 127.0.0.1 - - [09/Sep/2020 15:09:35] ...

Sending a JSON request using Swift 3

I am in need of posting JSON data that has the following structure: { "orders":[ {"id": 208, "quantity": 1 },{"id": 212, "quantity": 2},{"id": 202, "quantity": 5}, ...etc ],"HHStatus": "1 } Currently, I have a variable called orders : [ShoppingCart] = [] ...

Has jQuery UI Accordion taken over the design of unordered lists?

I'm having trouble with my website's navigation styling getting messed up by the jQuery accordion. The unordered list inside the .accordion div is overflowing and losing its CSS styling. I've tried adding clearStyle true and autoHeight false ...

The pre-loader is hidden behind the block content and navigation bar

I've encountered an issue with my preloader where it's loading in front of the <body> element but not in front of the site's <navbar> or the {% block content %}. The CSS snippet to increase the z-index of the preloader is as foll ...

Is it possible to create a CSS checkbox without using an ID or "for" attribute

Is it possible to create a CSS checkbox with label without using id and for attributes? I have tried the following method, but it doesn't seem to work. I know that I can create a CSS checkbox with id and for attributes like this: <div class="chec ...

Navigating through the website has become quite challenging due to the malfunctioning navigation bar. Instead

I recently completed a website and designed an awesome navigation bar in a separate file. However, when I combined them together, the navigation bar disappeared. The background of my "list" div should be filled in and larger, but it's not working as e ...

What is the method for ensuring a p element is only as wide as necessary when it wraps within a parent div with a specified hardcoded width?

Is there a way to adjust the width of the p-element in my example below based on the text inside without affecting the normal line break behavior, using only CSS if possible? It appears to be ignoring wrapping and is too wide: https://i.stack.imgur.com ...

Activate hover event on UI-Grid for interactive display

I often utilize in the following manner: <div ncy-breadcrumb class="title-shadow"></div> {{ getDeviceTree }} <div> <div ui-grid="gridOptions" ui-grid-resize-columns ui-grid-selection></div> </div> My object ...

Tips on how to maintain the underline when text is split into two sections

Revised This question is distinct from the duplicate one. I am specifically addressing the issue of ensuring the underline continues until the end of the text, regardless of how many lines it spans. The challenge I am facing is with displaying the underl ...

Adjustable height within embedded object tag

I've been struggling to adjust the height of the content on my site automatically. I have attempted using iframes as well, but nothing seems to work despite trying numerous code examples from various sources including CSS and JS scripts. Any help wou ...

Challenges arise with the Boostrap grid system, overflow scroll functionality, and responsive design when incorporating specific heights (vh) in elements

Attempting to implement a two-column layout using Bootstrap 4 that incorporates an overflow scroll feature when the height of a parent container is specified. You can view the fiddle here: https://jsfiddle.net/zeropsi/g19kzpsh/ The challenge I'm fac ...

Decoding JavaScript elements embedded in an HTML website

My current HTML site includes the following code: <script type="text/javascript"> jwplayer('player_container').setup( { 'width': '640', ...