Why this 100% width image is bigger than screen width * device pixel ratio

Cesar

I'm sure I'm missing something here.

Why this 100% width image is bigger than window.screen.width * window.devicePixelRatio

If the screen width equals to 360px and the device ratio is 2

Shouldn't this 100% width image equals to 720px instead of the reported 964px

Fixed Width Images

Also if I put a 720px image it does not cover the full device width???

Note that this is on my real device, a moto g4 play with a 720x1280 screen resolution enter image description here

EDIT

When I run this code, the reported width if the image is 964px in my case.

This code is also here http://li209-135.members.linode.com/

It should be viewed in a mobile browser.

<!DOCTYPE html>
<html>
<head>
	<title>Test</title>
	<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js"></script>
	<script>
		$(function(){
		  $('#log').append('<p style="font-size:2em;">Screen Width: ' + window.screen.width + '</p>');
		  $('#log').append('<p style="font-size:2em;"> Device Pixel Ratio: ' + window.devicePixelRatio + '</p>');
		  $('#log').append('<p style="font-size:2em;"> Image Width: ' + $('#test-image').width() + '</p>');
		});
	</script>	
</head>
<body>
	<img id="test-image" width="100%" src="http://via.placeholder.com/100x100">
	<div id="log"></div>
	<br>
	<img id="test-image" width="360px" src="http://via.placeholder.com/360x100">	
	<br>
	<img id="test-image" width="720px" src="http://via.placeholder.com/720x100">

</body>
</html>

Kornel

The dimensions are scaled or fake, because mobile browsers emulate desktop browsers for compatibility with non-mobile pages.

By default, pages in mobile browsers are rendered on a 960-pixel wide virtual screen, which is then scaled down to the actual screen size (or zoomed, etc.). This article describes this process in depth: https://www.quirksmode.org/mobile/viewports.html

To have your page dimensions closer to the actual device screen size, you need to add:

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Background image width is bigger than 100vw

My width is bigger than my screen, but body and html are set to 0 padding and margin and 100% width

Edge element width bigger than screen width on smallest screen size

width: 100% child bigger than parent

Android ImageView setLayoutParams with width bigger than Screen

Why is width of page larger than screen width?

Responsive Design: max-device-width, max-width and min-device-pixel-ratio

What is the view port width, height and device pixel ratio for the devices Google Pixel and Google Pixel XL

Width 100% is larger than the screen size

width: 100% of an absolute positioned element is bigger than the parent

How to test "if the width of the svg is bigger than the screen one"?

Why is {{ width: "100vw", height: "100vh"}} bigger than my browser window?(margin:0 not being applied)

Hide image if its height is bigger than its width

Why Is My Content Less Than 100% Width?

Why is path stroke width bigger on MS Edge than other browsers?

Why flexbox child have width bigger than parent

React Native - How to maintain image ratio with width = "100%"?

Maintain Aspect ratio for width @ 100%

Android: How to stretch an image to the screen width while maintaining aspect ratio?

SwiftUI Image AspectFit ratio not working properly with screen width

Layout constraint to resize image to screen width maintaining aspect ratio

Why is my table occupying more than 100% width of the body on small screen?

Chrome iPhone 6 emulator 100% width is wider than device

max-width of 100px vs width of 100px , why max-width is shorter than width?

Why is the page bigger than the screen?

How to make ScrollView width = to device screen width?

How to resize an image so it is always the biggest possible without the being bigger than the window height OR than the window width?

Element bigger than Page's width

CSS: stretching background image to 100% width and height of screen?