使用CSS媒体查询检测屏幕宽度 [英] Detect screen width with CSS Media Queries
本文介绍了使用CSS媒体查询检测屏幕宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我猜这是因为你可以用媒体查询:
I'm guessing that because you can do this with Media Queries:
@media (min-width:500px) { … }
在某些时候,CSS样式表必须知道屏幕的宽度, sans Javascript。
That at some point or another, the CSS stylesheet must know what width the screen is, sans Javascript.
是这样的吗?
推荐答案
使用 设备宽度
测试屏幕宽度(以px为单位)。然而,这不是完全推荐。请改用 max-width
和 min-width
(视口)。
如果你试图获取屏幕宽度并使用它(类似 content:(device-width); $ c
If you are trying to GET the screen width and use it (something like content: (device-width);
of some sort, that's not possible. Stick with JavaScript.
Manual Reference
这篇关于使用CSS媒体查询检测屏幕宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文