When the viewport's initial zoom is not set to 1, the values for Vh and Vw

I need an overlay that covers the entire screen.

width: 100vw;
height: 100vh;

The website I'm working on is not responsive and has a fixed width of 1000px. I have set the meta tag as:

<meta name="viewport" content="width=device-width" />

This loads the site at 1000px wide but uses the device viewport to enable the use of media queries and javascript for feature control.

The problem is that 100vh only equals the viewport when the pixel ratio is 1:1 and not zoomed out, making my 100vh/vw values smaller than the actual viewport size.

Is there a way to cover the viewport regardless of zoom level, while still detecting smaller screens?

It's important to note that this issue occurs specifically on mobile browsers, as mentioned by @Benjamin Solum.

https://i.sstatic.net/g1g87.png

Answer №1

It's interesting to note that the viewport width and height dimensions remain unchanged after zooming, as this seems to be a matter of how browsers are implemented.

While the width and height properties appear to be more closely tied to DOM elements themselves, it may be necessary for browser developers to reconsider how vw and vh are handled.

However, there could be valid reasons for maintaining the current behavior, particularly in cases where it proves useful. Finding a solution for scenarios involving zoom and non-responsive pages may therefore be challenging.

Answer №2

If you want a full-screen overlay, the best way is to use absolute positioning:

.overlay {
  /* To ensure it covers the whole screen */
  background: #f00;
  /* Positioned absolutely in relation to the viewport */
  position: absolute;
  /* Set edges to extend all the way to the viewport */
  top: 0; right: 0; bottom: 0; left: 0;
}
<div class="overlay">Hi!</div>

There's no need to worry about viewport metas or anything like that when using this method.

For a fixed position that remains in place regardless of scrolling, as Benjamin Solum suggested, you can use position:fixed.

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

In HTML, the size and position of an <a> element cannot be altered or adjusted

I am having trouble with an anchor element that is contained within a div. No matter what I try, I cannot resize or move it up or down without it covering its sibling element. I have attempted using transform-translate and margin properties, but to no avai ...

Avoiding applying the Textarea Transition on Resize is crucial

Currently, I am working on a Reactjs contact page where I have implemented a focus effect and transition for the textarea. However, I am facing an issue - when I resize the textarea, the transition is also applied to it, which is not desired. I have added ...

Center-align the table element

I've been struggling to center align this table element, specifically the one containing the square, but nothing seems to be working. Can anyone lend a hand in fixing this issue? <table> <tbody> <tr> <td>TURKEY - SU ...

Reduce the size of text using HTML and CSS

I'm currently working on replicating an image using HTML and CSS that will be placed beneath the avatar on a forum. Here is what I have managed to achieve so far: https://jsfiddle.net/J7VBV/220/ table.avatarStats { border-spacing: 0; border- ...

Spreading activity among react elements

Recently, I decided to repurpose a login/register modal by incorporating a Modal to manage its visibility. In the index.js file, I made the following changes: const Form = ({ initialState = STATE_SIGN_UP, showPopUp = STATE_HIDE }) => { const [mode, t ...

Challenge with the desktop sidebar in a responsive design

Disclaimer: Seeking input on how to address this issue kindly suggest another title for editing Situation I have a responsive design layout for mobile and desktop with different blocks: Mobile | block1 | | block2 | | clientInfos | | eq ...

Add an arrow or triangle at the tip of the line

I am currently working on recreating the design of lines with an arrow or triangle at the end side of an Input form. The inspiration for this comes from an old flash application that is now being converted to HTML5: https://i.sstatic.net/OCpif.jpg So far, ...

An effective approach to automatically close an Expansion Panel in an Angular Mat when another one is opened

I am attempting to implement functionality where one expansion panel closes when another is opened. By default, the multi attribute is set to "false" and it works perfectly when using multiple expansion panels within an accordion. However, in this case, I ...

Issues encountered with Element clicking in Span Div CSS dropdown frame using Selenium Web Driver

I am facing a challenge with a sophisticated epiphany web application that is only compatible with IE. The user interface involves multiple frames, one of which contains a Button that, upon being clicked, reveals a set of menu options. Here is the HTML cod ...

The foundation gem is encountering an issue with incompatible units: 'rem' and 'px'

After installing the foundation gem version 5.5.2.1, I encountered an error when starting the application: Showing /home/user/Scrivania/sites/store/app/views/layouts/application.html.erb where line #9 raised: Incompatible units: 'rem' and &apos ...

The div does not allow elements to be centered

I am facing an issue where elements are not centering on my div. I have tried numerous solutions (so many that I finally decided to create a Stack Overflow account), but nothing seems to work. Interestingly, the elements center on PC but for some reason, ...

Is it difficult to present certain fields in a side-by-side format?

When choosing fields for child age, two select fields are displayed but they are not inline side by side. I want them to be displayed inline, like the first two select fields. Here is my code: function addFields() { var number = document.getElementById( ...

Using Bootstrap to handle opening a link when a dropdown menu button is clicked

Utilizing Bootstrap in my main menu was essential for navigating through the numerous pages, subpages, and sub-subpages within my project. The dropdownmenu feature proved to be very helpful in this regard. However, my client now has a specific request - t ...

Utilizing Inline Placement within Email Templates

Seeking assistance in finding an alternative method to achieve the desired functionality in an email template. Having trouble with inline position styling being removed. table { width: 80%; border-spacing: 0; } table tr td.label-dots { positio ...

Tips for zooming out a Bootstrap 4 table

I am working with a bootstrap table that looks like this: <div class="table-responsive"> <table> .... </table> </div> Current display on mobile: https://i.sstatic.net/6b6qa.png desired display on mobile: https:// ...

CSS not being applied to Next.js HTML pages

Currently, I am utilizing Nextjs and including the flaticon css in _app.js as follows: import '../public/assets/css/flaticon.css'; In the upcoming section, an error is being encountered: @font-face { font-family: 'Flaticon'; src: ...

Creating a responsive two-column grid in Bootstrap 4.4 is a straightforward process that

Currently using Bootstrap 4.4.1. Experimented with a 2-column layout: Image on the left and Text on the right. <section class="resume-section-first p-3 p-lg-5 d-flex align-items-center" id="about"> <div class="w-100"> < ...

Is there a method for converting HTML/CSS into an image file?

My issue involves an unordered list (<ul>) with styled list items (<li>) that may have their properties changed through CSS manipulation (such as adding a different background on click using jQuery). I am currently using the TCPDF library to g ...

Cutting imagery to create a new design element

https://i.sstatic.net/IAh0h.jpg There is an image above with 6 gears (circles with pointy edges). My goal is to separate them into individual pictures and, on each picture's hover, have a relevant line with text appear. How can I achieve this? The a ...

React Native Transparent Modal Issue: Solution Needed

Recently, I encountered a problem with using a Modal to disable interactions on a screen while keeping everything visible. Oddly enough, it was working perfectly fine before, but when I attempted to turn the Modal into its own component, things took a turn ...