Experiencing inconsistencies with CSS on certain devices?

When faced with a research issue, I usually turn to Google for answers. However, this time, I was unsure of where to begin.

As part of my efforts to enhance my frontend development skills, I undertook The Odin Project and worked on a calculator project. Using a CSS grid to organize the buttons and display box, I considered breakpoints that could cause overflow on the screen:

.calculator {
height: 100vh;
height: calc(var(--vh, 1vh) * 100);
display: grid;
grid-template-columns: repeat(4, 100px);
grid-template-rows: 120px repeat(5, 100px);
justify-content: center;
align-content: center;
}

@media (max-width: 400px), (max-height: 620px) {
.calculator {
    grid-template-columns: repeat(4, 80px);
    grid-template-rows: 100px repeat(5, 80px);
}

button {
    font-size: 1.8em;
}
}

@media (max-width: 320px), (max-height: 500px) {
.calculator {
    grid-template-columns: repeat(4, 60px);
    grid-template-rows: 80px repeat(5, 60px);
}

button {
    font-size: 1.6em;
}
}

I conducted tests using responsive design mode on my browser, which appeared successful. Yet, when I checked on my phone, the display was considerably smaller than expected.

To investigate further, I clicked on the iPhone option in responsive design mode, confirming the size discrepancy. However, upon manual window resizing, the layout displayed correctly based on the CSS specifications above.

You can try it out yourself at

The complete code is available on my GitHub repository at https://github.com/cstobler/calculator

An additional detail you may notice is the custom --vh style property set in the body. This is established using the following JavaScript:

const setVH = () => document.body.style.setProperty("--vh", `${window.innerHeight * 0.01}px`);

setVH();

window.addEventListener("resize", setVH());

Incorporated into the height calculation within the CSS, this solution addresses viewport issues associated with the iOS address bar. Although applied before encountering the problem, I learned from CSS Tricks that it can resolve such issues.

Despite extensive testing, I am unable to determine the root cause or solution to this complication. Any guidance would be greatly appreciated.

Thank you in advance,

Charlie Tobler

Answer №1

It appears that the issue stems from display scaling on devices equipped with "retina" displays.

If you fail to specifically instruct the browser to adapt for the higher density display, it will treat 1px as 1px, resulting in a halved interface size (due to the doubling of pixels in the same area on iPhone screens).

To address this problem, inserting the following meta element within the head section of your webpage seems to solve the problem:

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

For further information, refer to MDN: Using the viewport meta tag to control layout on mobile browsers

If anyone can provide a more comprehensive explanation or technical details regarding this issue, please feel free to modify my response accordingly.

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

Customizing CSS float labels for individual inputs

For my project, I've implemented CSS code to create a floating label effect for form inputs. If you need the original code reference, it can be accessed here. However, since there are multiple examples in the original codebase, I have extracted and m ...

Choose either nth-child or nth-of-type within a nested element

Here is the HTML code snippet: <div class="homepage-body"> <a href="#"> <div class="homepage-item"> <div class="homepage-icon"></div> <div class="homepage-text"> Test1 </di ...

Prevent overlapping of range sliders in HTML and CSS

I have designed a range slider with two buttons, but they are overlapping each other. I want to ensure that they do not cross over one another - where the value of the first button should be equal to the minimum value of the second button, and the maximum ...

Bringing together embedded chat and stream seamlessly with CSS styling

I'm in the process of integrating a chat feature with my Twitch stream on a Xenforo forum page. I aim for the stream to be displayed in 16:9 aspect ratio to ensure high definition quality, and I want it to adapt to the user's screen resolution. B ...

Unable to vertically align images in the carousel

Greetings! I am currently working on my website www.acigaiabeta.esy.es and I am facing an issue with aligning the images of the carousel to the center vertically. Despite trying various solutions, such as following tips from this resource, the images remai ...

Position the float input to the right on the same line as an element

This Angular code contains a challenge where I aim to have text at the start of a column and an input box on the right side of the page, both aligned on the same line. The issue lies in the code which floats the input to the right but disrupts the alignme ...

Designing draggable tags similar to those on LinkedIn, incorporating a parent div element containing an SVG image and text

Lately, I've been exploring the world of CSS and Angular. Can someone give me a jumpstart on using CSS to design an element like the one shown in this https://i.stack.imgur.com/vcR3Z.png image? Essentially, this outer tag consists of a div element th ...

Ways to ensure that two divs have equal heights based on whichever one has the greater height using CSS

I need help with adjusting the heights of two divs inside a container div using CSS. Specifically, I want the height of the img_box div to match the height of the content_con div based on their actual content. For example, if the content_con div contains t ...

What is the best way to resolve the CSS border styling issue surrounding the anchor element?

I created a simple sign-up form for my school project where users can choose their roles. I'm facing an issue with the border under the anchor tag and I need help fixing it. How can I ensure that the space at the top is equal to the bottom as well? T ...

CSS does not alter the properties of a link's "background-color" or "border-color"

I have successfully changed the text color of visited links, but I am struggling to change the "background-color" and "border-color" properties. The initial part of my internal style sheet includes a CSS reset. a:visited { color: red; background-col ...

Modifying Row Color in Bootstrap 3: A Step-by-Step Guide

I'm trying to customize the background color of alternating rows in a Bootstrap 3 grid. I attempted to use CSS and add it to the class within the div, but unfortunately, the color isn't changing as expected. Below is the CSS code I used: .row-b ...

Align a div to the center horizontally at the top of the screen

Is there a way to vertically center text within a div and also horizontally center the div at the top of the screen? Visit this link for more details <div id='custom'> example text </div> #custom{ width: 50%; background: #FF00 ...

Resizing the elements within an iframe: Troubleshooting problems with embedding Bandcamp players

My goal is to embed a Bandcamp music player on my WordPress blog page, but I'm facing a challenge. The maximum width of the current player is 700px and I need it to be 900px. After consulting with someone at Bandcamp, they directed me to the old versi ...

What causes an image's size to change when it floats within the parent container?

There seems to be a height mismatch issue between the container and the image inside it when the parent is floated, but not the child. However, when both are given the float property, the height matches perfectly. Why is this? <div class="parent">&l ...

Is there a way to modify the dimensions of this container? (CSS)

After performing a search and clicking on a result, a white bubble pops up on the map. I am looking to use CSS to make this bubble smaller as it is currently too large. Can anyone provide guidance on how to achieve this? ...

What is the best way to conceal a canvas or another item?

Within my main canvas, there are three smaller canvases and a text element. <canvas id="Background" width="350" height="300" style="border:6px solid black; position: absolute; left: 10px; top: 10px;"> </canvas> <canvas id="Canvas1" width ...

Tips for aligning text to the right and button to the left while ensuring responsive design with CSS

Trying to align text on the left and the button on the right with space between them in a responsive card design. The button has a background image added to it. Here is my attempted CSS, but the design is not yet fully responsive: .component { disp ...

Ensuring that the empty bubble remains undisturbed, here's a guide on effectively implementing the if

I need assistance with adding an "if condition" to my text field. The condition should prevent the empty bubble from appearing when the send button is clicked. function verifyInput(){ var currentText = document.getElementById("demo").innerHTML; var x ...

Ways to determine the height of a responsive div's background image

I have a container with a background image. Inside this container, there are additional elements like my navigation bar. My goal is to make the container have the same height as the background image. I've attempted the following: .bg { ...

Modifying Margin and Spacing for Selections in Radio Buttons

I have successfully implemented the code for a radio button, and everything is working as expected div > label { margin-right: 80px !important; box-shadow: .3rem .3rem .6rem #c8d0e7, -.2rem -.2rem .5rem #FFFFFF; position: relative; ...