Viewport Orientation: Device Alignment in Portrait or Landscape Mode

I am experiencing an issue with the viewport on an iPhone 8 Plus. The code below functions properly on an iPad Air 3 (2019). However, when I rotate the iPhone 8 Plus or an iPhone XS Max in landscape mode and then back to portrait mode, Safari and Firefox browsers add additional space on the portrait screen but not on the landscape screen. What's more intriguing is that this behavior only occurs if no additional tab is opened and not in every case. Any insights into why it behaves this way?

<!DOCTYPE html>
<html lang="de">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Titel</title>
    <style>
        * {
            
            padding: 0;
            margin:0;
        } 
      
     </style>
  </head>
  <body style="height:100%; background-color:grey;display:grid;grid-template-rows:120px 60px calc(100% - 180px)">
      <div style="background-color:green;height:100%;"></div>
      <div style="background-color:red;height:100%;"></div>
      <div style="background-color:blue;height:100%;"></div>
  </body>
 <script>
    
      let winGroesse = window.innerHeight;
      let winGroesseout;
          
      window.onresize = reSizeFunkt;
      
      let neueWinGroesse = winGroesse.toString() + "px";
      
      document.querySelector('html').style.height = neueWinGroesse; 
        
      function reSizeFunkt () {
          
          winGroesse = window.innerHeight;
          
          neueWinGroesse = winGroesse.toString() + "px";
         
          document.querySelector('html').style.height = neueWinGroesse; 
           
          
      }
    
    
</script>   
    
</html>

before rotating after rotating

Answer №1

After extensive testing, I have yet to discover a definitive solution to the problem at hand. However, should anyone else encounter a similar issue, I am sharing my less-than-ideal workaround below:

let winSize = window.innerHeight;
let winSizeOutput;

window.onresize = resizeFunction;

let newWindowSize = winSize.toString() + "px";

document.querySelector('html').style.height = newWindowSize; 

function resizeFunction () {

    winSize = window.innerHeight;

    newWindowSize = winSize.toString() + "px";

    document.querySelector('html').style.height = newWindowSize; 

    setTimeout(function() {
        winSize = window.innerHeight;
        newWindowSize = winSize.toString() + "px";
        document.querySelector('html').style.height = newWindowSize;
    }, 300);

};

Through my experimentation, I have found that the resizing action requires a brief moment to take effect. Therefore, I implemented a secondary function with a delay of 300ms. While this workaround achieves the desired result, I believe there must be a more elegant solution available.

I remain optimistic that a more effective and streamlined resolution will present itself in due time.

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

Change to a dark theme using React hooks in typescript

Hello, I am new to React and English is not my first language, so please excuse any mistakes. I have been trying to enable a dark mode feature on my website. Most examples I have found involve toggling between dark and light modes where you need to specify ...

anticipating the completion of a task in order to proceed with the next one

I have been attempting to sequence the execution of two functions, but both are running concurrently with my main function. The console is displaying 2, then 1, when it should be 1 first. How can I make sure that the complete function waits for fetchingFun ...

Entire body encompassing table

I am trying to create an HTML page with a table that spans the entire body and displays scrollbars when needed for both horizontal and vertical scrolling. Here is my current styling for the table: table { box-shadow: inset 0 0 10px #000; position: ...

Executing SQL Query on Button Click Event

I am working with PHP and trying to execute a SQL query when a button is pressed. However, the issue I'm facing is that nothing happens when I click the button! I checked the developer console but there doesn't seem to be any action detected when ...

Everything written below the CSS code

I am trying to create a layout where a line of text is aligned directly underneath another line of text. Here is the HTML code: <h4 class="support1">Number 123456</h4> <h4 class="support2">Number 678910</h4> This is the CSS code ...

"Encountered an issue with submitting the nodejs form

edit 2 After attempting to implement the following code snippet in my nodejs application, I encountered an issue where the form data was not being successfully posted to the database: router.get('/dashboard/users/forms/competition-form/:id', en ...

Place a gap between each image

I currently have three posts on my front page, each spanning the full width of the page. I want to add a 30px padding to the left of these posts, but I'm facing an issue where there is also a 30px padding at the beginning of each row. My goal is to on ...

Implementing Bootstrap Datepicker within the dynamically generated table rows

I am currently in the process of developing a data grid for a project and I am encountering an issue with implementing Bootstrap Datepicker on the Date field within the table. The problem arises when trying to use the datepicker on subsequent rows that are ...

Using CSS3 to clear floats without altering the HTML structure

Despite searching for multiple solutions to this issue, I have yet to find one that works without requiring me to modify my HTML code. Here is the current HTML in question: <div class="name">Daiel</div> <div class="amount">30€</div ...

The challenge of navigating CSS specificity guidelines

In my CSS file, I have defined two styles for a table with the class "myTable". The first style sets the background color of header cells to gray, while the second style sets the background color of odd rows to blue: .myTable th { background-color: gr ...

CSS Animation Effect on Transparent PNG Image

Today, while working on my website, an interesting CSS effect came to mind. I vividly remember seeing it a few months ago, but unfortunately, I couldn't find it among my bookmarks. The website featured a captivating design with a prominent logo that ...

What is the best way to implement two distinct global CSS styles for separate pages in Next.js?

I'm looking to give my website a fresh look by creating two different global CSS styles. Is it possible to use one CSS style for the old pages and another for the new pages? ...

Tips for modifying the audio session category in iOS using React Native

When using React Native, I know that to allow background audio playback (especially for react-native video), I need to adjust the audio session as outlined here in the Apple development documentation. However, I'm unsure of where to integrate the Obj ...

Name of Gadget for iPad Mini Retina

When calling uname() on IOS, it will return the device name. I have been searching for information and the only documentation I found is available on this website. However, I noticed that the iPad Mini Retina is not listed there. Can anyone confirm what u ...

Troubleshooting CSS rendering issues on Chrome browser

Currently in the process of developing a new website based on an old template. The site appears as intended in IE, Safari, and Firefox, but for some reason Chrome is not rendering any of the css. Just to clarify, none of the links are functioning at this ...

Steps for configuring UI-Router to open a new tab

I have a link on the homepage that directs users to a second page with two tabs. I want the second tab to be active by default so that users can see its content immediately. I tried using ui-sref, but it only takes me to the second page without activating ...

What's the reason for the icon not updating in the responsive mode?

I am venturing into the world of responsive web design for the first time. My aim is to create a website menu that drops down when the menu icon is clicked, using the onclick command in JavaScript. However, upon inspecting my browser, I noticed an uncaught ...

Adjust the UITableViewCell height whenever there is a change in the label text

Hey there, I'm currently facing an issue regarding updating the height of a UITableViewCell whenever the text in its label changes. Explaining things isn't my strong suit, so I've created a repository on Github where you can simply download ...

The visual effects that accompany the addition of a new class

My web app features two distinct modes: visual and interactive. By default, the app is in visual mode. When a user switches to interactive mode, I apply the "interactive" class to the container div. This triggers the display of hidden divs that were not vi ...

What could be causing certain text to vanish (become invisible) when viewed on a mobile device?

How can I make sure all text is visible on a mobile device? I need the text to display in full size when testing on a mobile device. How do I achieve this? <html> <head> <meta content="width=device-width,initial-scale=1,minimum-scale ...