Is a CSS pixel really an absolute unit? That is, is 1 inch = 96px true?

后端 未结 3 1609
萌比男神i
萌比男神i 2020-12-14 17:03

The official W3C documentation says:

1 px = 1/96th of 1 in

In my previous 18.5 inch screen, the screen.width was

相关标签:
3条回答
  • 2020-12-14 17:19

    A Css pixel unit is not necessarily a physical pixel measurement,(in my answer i am addressing css px for screens and not print)

    For a CSS device, these dimensions are either anchored (i) by relating the physical units to their physical measurements, or (ii) by relating the pixel unit to the reference pixel.

    In the above explanation the reference pixel is explained as follows

    The reference pixel is the visual angle of one pixel on a device with a pixel density of 96dpi and a distance from the reader of an arm's length. For a nominal arm's length of 28 inches, the visual angle is therefore about 0.0213 degrees. For reading at arm's length, 1px thus corresponds to about 0.26 mm (1/96 inch).

    more explanation is here

    For a simple example lets take an iPhone 8

    Phy px 750 X 1334

    CSS px 375 X 667

    As you can see physical px measurements is completely different from Css px. Ratio between actual physical pixel and css pixel is called pixel ratio, which is determined based on viewing angle, distance it is viewed from and display resolution.

    At the end of the day hardware vendor has this set depending on the above mentioned aspects.

    Here is the link to the list of devices with phy px , css px and their pixel ratio.

    The objective for all of this is to have a more consistent display through out different hardware.

    And finally as documentation from w3.org points out:

    Note that this definition of the pixel unit and the physical units differs from previous versions of CSS. In particular, in previous versions of CSS the pixel unit and the physical units were not related by a fixed ratio: the physical units were always tied to their physical measurements while the pixel unit would vary to most closely match the reference pixel. (This change was made because too much existing content relies on the assumption of 96dpi, and breaking that assumption breaks the content.)

    In earlier versions Css pixel was heavily based on reference pixel which was based under the assumption its always 96dpi.Here instead css px and phy px are related by pixel ratio.

    Hope this helps.

    0 讨论(0)
  • 2020-12-14 17:32

    As specified slightly further down the part of the CSS Values and Units Module you've already linked, there are two different implementations that can be applied with CSS:

    For a CSS device, these dimensions are anchored either

    i. by relating the physical units to their physical measurements, or
    ii. by relating the pixel unit to the reference pixel.

    This goes on to note:

    If the anchor unit is the pixel unit, the physical units might not match their physical measurements. Alternatively if the anchor unit is a physical unit, the pixel unit might not map to a whole number of device pixels.

    And finally, it concludes:

    The reference pixel is the visual angle of one pixel on a device with a pixel density of 96dpi and a distance from the reader of an arm’s length. For a nominal arm’s length of 28 inches, the visual angle is therefore about 0.0213 degrees. For reading at arm’s length, 1px thus corresponds to about 0.26 mm (1/96 inch).

    This means that the pixel unit is an absolute length, but its length can change depending on whether the device applies implementation i or implementation ii from the first part I've quoted here.

    An absolute length, as defined by the CSS Values and Units Module, is simply a length which is “anchored to some physical measurement”. The physical measurement will either be their actual physical length or the length derived by the reference pixel.

    The same section of the specificaiton also says:

    For print media and similar high-resolution devices, the anchor unit should be one of the standard physical units (inches, centimeters, etc). For lower-resolution devices, and devices with unusual viewing distances, it is recommended instead that the anchor unit be the pixel unit. For such devices it is recommended that the pixel unit refer to the whole number of device pixels that best approximates the reference pixel.

    96px will not always equal 1 real-life inch.

    0 讨论(0)
  • 2020-12-14 17:36

    No, px is a relative unit. As pixel size is different for different screen sizes they (maybe W3C) set a standard for px as a relative unit.

    0 讨论(0)
提交回复
热议问题