我正在尝试使用“分辨率”媒体查询来确定屏幕的实际DPI。
我正在执行的代码如下:
window.matchMedia(`(resolution: ${value}dpi)`).matches
但是我发现在两个不是具有相同DPI的不同设备上,此查询为真的value
为96。例如,在一台机器上,实际DPI为157。这两个机器上的window.devicePixelRatio
等于1。在第三个设备上,实际DPI为215,但是上面的查询告诉我它是192(精确为96的两倍),而window.devicePixelRatio
是2。
我看到过CSS媒体查询看起来像“ @media”或“ @media screen”,但是如果我将其中任何一个放入字符串中,都传递给matchMedia
,无论价值是。但是我觉得我必须缺少一些东西,因为规范说resolution
是为了匹配屏幕的实际分辨率,而我从来没有看到这种情况。
答案 0 :(得分:2)
CSS <table role="presentation" cellspacing="0" cellpadding="0" border="1" width="110">
<tr>
<td>
Office of Admissions<br>
One John Marshall Drive<br>
Huntington, WV 25755<br>
1-877-GOHERD-1<br>
<a href="mailto:admissions@marshall.edu">admissions@marshall.edu</a>
</td>
</tr>
<tr>
<td style="padding: 2px;">
</td>
</tr>
<tr>
<td>
<table role="presentation" cellspacing="0" cellpadding="0" border="1" width="96">
<tr>
<td width="24">
<a href="https://www.facebook.com/marshallu" target="_blank">
<img alt="Facebook" src="http://www.marshall.edu/admissions/files/Facebook-grey.jpg" width="22">
</a>
</td>
<td width="24">
<a href="https://twitter.com/marshallu" target="_blank">
<img alt="Twitter" src="http://www.marshall.edu/admissions/files/Twitter-grey.jpg" width="22">
</a>
</td>
<td width="24">
<a href="https://www.linkedin.com/company/19059?trk=tyah" target="_blank">
<img alt="LinkedIn" src="http://www.marshall.edu/admissions/files/LinkedIn-grey.jpg" width="22"></a>
</td>
<td>
<a href="https://www.instagram.com/marshallu/" target="_blank">
<img alt="Instagram" src="http://www.marshall.edu/admissions/files/Instagram-grey.jpg" width="22">
</a>
</td>
<td width="24">
<a href="https://www.snapchat.com/add/marshallulife" target="_blank">
<img alt="Snapchat" src="http://www.marshall.edu/admissions/files/SnapChat-grey.jpg" width="23">
</a>
</td>
</tr>
</table>
</td>
</tr>
单位基于CSS单位,而不是实际的物理尺寸。
因此,如果我们忘记了DPI是打印单元这一事实,因此当它与屏幕相关时,它应该称为PPI,<resolution>
不会向您显示。
实际上,此单位实际上是多少<resolution>
(其中pixels per CSS inch
是显示屏上最小的物理点),而pixel
被定义为CSS inch
(其中{ {1}}是不可思议的CSS单位,而不是任何物理物体。
因此,您所拥有的只是96px
,并且不会为您提供有关屏幕物理密度的任何信息(这需要您的浏览器知道显示器的实际物理尺寸,即不可能,因为简单的事实,您可以使用光束投影仪作为显示)。