Adjusting the browser window height

I'm puzzled as to why setting the height viewport property like this:

<meta name="viewport" content="width=480px, height=120px">

isn't effective. Even though window.innerWidth correctly reports 480px, window.innerHeight shows 210 instead of the expected 120px! This makes me question the purpose of setting the height property at all.

Answer №1

Due to the absence of height, this element is best suited for device compatibility rather than setting a fixed size. Media queries should be utilized for that purpose.

<meta name="viewport" content="width=device-width, initial-scale=1.0">
http://www.w3schools.com/css/css_rwd_viewport.asp

Answer №2

As mentioned in the previous comment, it is recommended to specify the width/height without using "px". See example below:

<meta name="viewport" content="width=500, initial-scale=1">

Keep in mind that a pixel may vary depending on the user's device.

For more information, refer to this article:

https://developer.mozilla.org/en-US/docs/Mozilla/Mobile/Viewport_meta_tag

Here is also a reference explaining the concept of pixels:

http://www.quirksmode.org/blog/archives/2010/04/a_pixel_is_not.html


EDIT: I might have figured out your issue. While adjusting the viewport properties, I observed that browser cache could have affected your testing experience. Make sure to clear the cache if needed. -- !!!Please read the NOTE at the END if you're testing on a non-mobile device!!!

To demonstrate a quick example, consider the following change:

<meta name="viewport" content="height=50">

I have set up 3 websites for you to check with the same div element:

All have the following CSS for the div:

div{
    width: 60px;
    height: 60px;
    background-color: #000;
}

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

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

<meta name="viewport" content="height=50">

NOTE: The viewport property, which specifies the size of the viewport, is primarily used by mobile devices only.

Make sure to test this on a mobile device for accurate results! If you used a regular browser, here is the explanation!

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

The Bootstrap carousel and column are having trouble sticking together side by side

Objective: My goal is to design a bootstrap layout featuring a carousel on the left and text blocks on the right. These sections are denoted as "Left Column" and "Right Column" respectively in the HTML comments. Challenge: I am facing difficulty ...

Changing text color dynamically when hovered over by referencing retrieved data

Hello, I'm having trouble with applying a className based on database values and using it in CSS for custom hover color. Can anyone assist me? ...

Adaptable CSS triangle design

Hello I'm looking to create a responsive CSS triangle similar to the image linked below. I attempted using percentages with border width, but didn't achieve the desired outcome. Can anyone suggest a simple solution? https://i.stack.imgur.com/Yah ...

Positioning elements on the web page using CSS tiles

Greetings! I am currently working on a website that utilizes tiles similar to this: https://i.sstatic.net/OzKQv.png Everything seems to be in place, except for one tile that is not aligning with the rest. I am struggling to figure out how to position it c ...

Display initial messages at the bottom of a DIV, with subsequent messages moving upwards

My Chat DIV is designed to send and receive messages. Currently, messages appear at the top of the DIV and move downwards (as shown in red). Once they reach the bottom, they are pushed upwards using the jQuery snippet below: .scrollTop(activeConversation ...

Capture Video on iOS devices using the MediaRecorder API and display it using HTML5 Video Player

Issue: I am facing an issue where I cannot record video or get a video stream from the camera on iOS through my Angular web application built using ng build. Investigation: In my investigation, I explored various websites that discuss Apple iOS features ...

Unable to utilize the ng-disabled directive

Although this question may seem redundant, rest assured that I have exhausted all possible solutions. The issue lies in a disabled button using ng-disabled. I have a variable in the $scope that triggers a change in the ng-disabled attribute, but it fails t ...

Animating the display and concealment of a Ui Bootstrap alert within an AngularJS modal window

Trying to create a dynamic animation for an ng-hide feature used on a Ui Bootstrap alert button within a Ui Bootstrap Modal is proving to be quite challenging. The goal is to have the alert slide in and out while simultaneously fading in and out. Although ...

Stopping a file transfer in case of browser closure or upload cancellation

When working on uploading a file asynchronously using HTML5 in MVC3, a common issue arises when dealing with large files such as 1GB. If the upload process is cancelled or the browser is closed at 50% completion, a 500MB file still gets saved in the target ...

Is there a way to assign a value to a select option in Angular 7?

The issue arises when attempting to modify the value, as it consistently displays the initial option selected. Here is the structure of my HTML code: <div class="col-lg-4 col-md-4 col-sm-12 mt-4"> <div class="form-group"& ...

The top content above the Bootstrap navbar fails to remain fixed in place

Seeking assistance with a Bootstrap 4 navbar and header setup. The goal is to have the navbar stick to the top while making the header disappear on scroll. In my functions.php file, I've enqueued Jquery for this project. Below is the CSS found in st ...

Performing a form submission on a dropdown menu using the onchange event without the need for

Is it possible to trigger a postback using an onchange event and then retrieve the value in a Request[]? Here is the code snippet: <select name="nameOnSelection" id="idOnSelection" onchange=""> <option value="1"> random string ...

Tables inserted via ckeditor do not preserve the style attribute

After incorporating ckeditor into my web page along with the table plugin, I noticed that sometimes the width of tables created in the editor window extends beyond the boundaries of the webpage when displayed. To address this issue, I made some adjustments ...

Transform the size and convert an object from a picture into text based on the user's scrolling

I've been intrigued by the scrolling effects used on websites like Google SketchUp and Google Plus. It's fascinating how elements can transform as you scroll down the page. For example, on Google SketchUp's site, the banner starts off integr ...

The CSS navigation bar is not properly aligned in the center

This menu was constructed by me: JSBIN EDIT ; JSBIN DEMO Upon closer inspection, it appears that the menu is not centered in the middle of the bar; rather, it is centered higher up. My goal is to have it positioned lower, right in the middle. I ...

Which library does stackoverflow utilize to showcase errors (utilizing Bootstrap popover for error help-block)?

Currently, I am using bootstrap's has-error and help-block classes to display validation error messages in my form. However, I find the error message display in Stackoverflow's Ask Questions Form to be very appealing. Are they using a specific js ...

In React Native, changing the translation of an element causes it to shift below all other elements, regardless of

Check out this sandbox project: I'm trying to create a simple animation using translation in React Native, but I'm facing an issue where when I move the element to the right and down, it goes under other elements. However, if I move it left and ...

Utilizing Javascript / jQuery to eliminate specific CSS styles

I am facing an issue with the CSS code for a table positioned at the bottom of the screen. The current code includes a filter specifically for IE 8, but I need to make it compatible with IE 10 as well by removing the filter and adding a background color. ...

What is the best way to enable drag-and-drop functionality for a button on an HTML

Recently, I wrote this code snippet: <!DOCTYPE html> <html> <script> score = 0 function hi(buttonID){ score += 1 document.getElementById("label123").innerHTML = score } < ...

Steps to display a full-page loader/spinner prior to the completion of loading a React application

What is the best way to create a full-page loader/spinner that will be displayed until a React (or other JS-based framework) app is fully loaded? By "fully loaded," I mean when the browser's spinner stops spinning. I have experience creating loaders ...