简体   繁体   English

Chrome 开发者工具中的图片尺寸

[英]Dimensions of Picture in Chrome Developer Tools

I'm working through Mozilla's tutorial on responsive images .我正在研究Mozilla 的响应式图像教程 Part of the tutorial explains how you can use the responsive design feature of a browser's developer tools to see the pixel demensions of an embedded image on various display sizes.本教程的一部分解释了如何使用浏览器开发人员工具的响应式设计功能来查看嵌入图像在各种显示尺寸上的像素尺寸。

It asks students to view their demo page in a browser, and open up the responsive design developer tool.它要求学生在浏览器中查看他们的演示页面,并打开响应式设计开发人员工具。 I'm using Chrome and did just that.我正在使用 Chrome 并做到了这一点。 I then set the screen demensions to 320 X 480 , and inspected the first picture in the body of the page.然后我将屏幕尺寸设置为320 X 480 ,并检查页面正文中的第一张图片。 However, Chrome says the dimensions of the picture are 800 X 464 .但是,Chrome 表示图片的尺寸为800 X 464 How can that be if the screen itself is only 320 X 480 ?如果屏幕本身只有320 X 480 ,那怎么可能呢?

Furthermore I tried it out in Firefox, and Firefox gives 280 X 162.4 .此外,我在 Firefox 中进行了尝试,Firefox 给出了280 X 162.4

So:所以:

  1. What are the units for all those demensions?所有这些维度的单位是什么? I presumed all the dimensions were in pixels, but a fractional pixel doesn't really make sense.我假设所有尺寸都以像素为单位,但分数像素并没有真正意义。
  2. Assuming the units are all the same, why is the picture larger than the screen in Chrome, and why does Chrome disagree with Firefox?假设单位都一样,为什么Chrome中的图片比屏幕大,为什么Chrome不同意Firefox?

In general, mobile browsers use the following strategy to display web sites that were not mobile-optimized: they render them as if the were displayed on a small desktop (ie on a "virtual viewport", usually 800 to 1000 pixels wide), and then scale the result down to fit in the mobile screen.通常,移动浏览器使用以下策略来显示未针对移动优化的网站:它们将它们呈现为显示在小型桌面上(即在“虚拟视口”上,通常为 800 到 1000 像素宽),以及然后缩小结果以适合移动屏幕。 There is a classic article "A tale of two viewports" (particularly, part two ) by Peter Paul Koch that explains it well. Peter Paul Koch 有一篇经典文章“两个视口的故事”(特别是第二部分)对此进行了很好的解释。

It appears that the Responsice Design mode of the Chrome's devtools assumes that this behavior is happening and the "virtual viewport" is 980 pixels wide. Chrome 开发工具的响应设计模式似乎假设这种行为正在发生并且“虚拟视口”是 980 像素宽。 Firefox doesn't do this, making the virtual viewport equal to the actual window size. Firefox 不这样做,使虚拟视口等于实际窗口大小。 Setting <meta name="viewport" contents="device-width"> makes all browsers (including real mobile ones) do the latter.设置<meta name="viewport" contents="device-width">使所有浏览器(包括真正的移动浏览器)都执行后者。

So:所以:

  1. The units are CSS pixels before the scaling.单位是缩放前的 CSS 像素。 Non-integer pixels make sense for calculations, when browsers renders them they get rounded.非整数像素对计算有意义,当浏览器呈现它们时,它们会被四舍五入。

  2. The picture is larger than the screen because the virtual viewport is scaled down.图片比屏幕大,因为虚拟视口缩小了。 This can be prevented by setting <meta name="viewport" contents="device-width"> .这可以通过设置<meta name="viewport" contents="device-width">来防止。

Mozilla Firefox developer tools is showing you the size of image which is actually shown where as Google Chrome developer tools is showing the actual image size. Mozilla Firefox 开发人员工具向您显示实际显示的图像大小,而 Google Chrome 开发人员工具显示实际图像大小。

so we can say neither Google Chrome nor Mozilla Firefox is wrong, they are just showing different image size because their designers have chosen to do so.所以我们可以说 Google Chrome 和 Mozilla Firefox 都没有错,它们只是显示不同的图像大小,因为它们的设计者选择这样做。

The downloaded image can be larger than what is displayed in your screen.下载的图像可能大于屏幕上显示的图像。 If a downloaded image is too large for the view space, it shrinks the image to fit.如果下载的图像对于视图空间来说太大,它会缩小图像以适应。

With Chrome 90, when hovering over an image URL in the Dev Tools Elements inspector, a tool tip will show Rendered size and Intrinsic size .在 Chrome 90 中,将鼠标悬停在 Dev Tools Elements 检查器中的图像 URL 上时,工具提示将显示Rendered sizeIntrinsic size Intrinsic size is the downloaded size.内在大小是下载的大小。

In Firefox hovering over an image URL in it's Inspector will show the actual image size (downloaded size) under a popup thumbnail of the image, and it will show the rendered size over the image in the page view.在 Firefox 中,将鼠标悬停在其检查器中的图像 URL 上将在图像的弹出缩略图下显示实际图像大小(下载大小),并将在页面视图中的图像上显示渲染大小。

On real mobile devices the rendered size is actually likely to be larger than these browser mobile views indicate.在真实的移动设备上,渲染的大小实际上可能比这些浏览器移动视图指示的要大。 As of writing mobile screen dimensions are commonly 1080 x 1920 pixels or even denser (The Google Pixel 5 has a FHD+ screen (1080 x 2340)).截至撰写本文时,移动屏幕尺寸通常为 1080 x 1920 像素或更密集(Google Pixel 5 具有 FHD+ 屏幕 (1080 x 2340))。 The browser mobile view is likely to indicate the view size is something like 320 x 480 (depending on which device is selected).浏览器移动视图可能会指示视图大小类似于 320 x 480(取决于选择的设备)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM