如何设置永远无法满足的媒体查询条件?
How to set a media query condition that can never be met?
如何在任何设备上创建一个永远不会被选择的媒体查询断点?
我见过人们使用 only speech
或 only screen and (min-width: 1000em)
之类的东西,但这些看起来像是等待发生的尴尬情况。我还想要对任何其他阅读代码的开发人员来说更干净、更直观的东西。
是否可以创建不可能的媒体查询?
如果有人想知道 "Why would you do this?",就我而言,这是因为我试图关闭第 3 方模块中的条件,该模块被硬编码为在如果满足某个媒体查询,则某个断点。基本上,它有一个不必要的宽屏视图,不必要地删除了有用的功能。
这个第 3 方模块不允许我关闭此条件或修改不良行为,而无需破解核心模块代码,这会随着未来的更新而中断,但它确实允许我覆盖其默认值带有任何字符串的媒体查询。所以,我正在寻找最干净的不可能的媒体查询来与不良行为相关联,这样它就永远不会发生。
not all
...逻辑上意味着 "not any device"。它似乎可以作为一个包罗万象的否定。
not all
经常用在像 not all and (some other condition)
(dev.mozilla gives some examples) 这样的结构中,意思是 "not if the other condition is true, on any device",所以它是一个完全有效的配对。
除了 OP 的答案外,媒体查询规范中还解释了 not
关键字。
The logical NOT can be expressed through the not
keyword. The
presence of the keyword not
at the beginning of the media query
negates the result.
User agents are to represent a media query as not all
when one of
the specified media features is not known.
使用此关键字可以轻松地 "set a media query condition that can never be met",如问题中所要求的。
工作原理如下:
@media not screen and ( min-width: 1000px ) { body { background-color: green; } }
这意味着在屏幕尺寸大于 1000px 的情况下,不要执行此代码。换句话说,媒体查询将在屏幕尺寸小于 1000px 时执行。相当于:
@media screen and ( max-width: 1000px ) { body { background-color: green; } }
无法同时匹配低宽和高宽所以我想:
@media screen and (max-width: 123px) and (min-width: 4321px) {
/* Never ever */
}
如何在任何设备上创建一个永远不会被选择的媒体查询断点?
我见过人们使用 only speech
或 only screen and (min-width: 1000em)
之类的东西,但这些看起来像是等待发生的尴尬情况。我还想要对任何其他阅读代码的开发人员来说更干净、更直观的东西。
是否可以创建不可能的媒体查询?
如果有人想知道 "Why would you do this?",就我而言,这是因为我试图关闭第 3 方模块中的条件,该模块被硬编码为在如果满足某个媒体查询,则某个断点。基本上,它有一个不必要的宽屏视图,不必要地删除了有用的功能。
这个第 3 方模块不允许我关闭此条件或修改不良行为,而无需破解核心模块代码,这会随着未来的更新而中断,但它确实允许我覆盖其默认值带有任何字符串的媒体查询。所以,我正在寻找最干净的不可能的媒体查询来与不良行为相关联,这样它就永远不会发生。
not all
...逻辑上意味着 "not any device"。它似乎可以作为一个包罗万象的否定。
not all
经常用在像 not all and (some other condition)
(dev.mozilla gives some examples) 这样的结构中,意思是 "not if the other condition is true, on any device",所以它是一个完全有效的配对。
除了 OP 的答案外,媒体查询规范中还解释了 not
关键字。
The logical NOT can be expressed through the
not
keyword. The presence of the keywordnot
at the beginning of the media query negates the result.User agents are to represent a media query as
not all
when one of the specified media features is not known.
使用此关键字可以轻松地 "set a media query condition that can never be met",如问题中所要求的。
工作原理如下:
@media not screen and ( min-width: 1000px ) { body { background-color: green; } }
这意味着在屏幕尺寸大于 1000px 的情况下,不要执行此代码。换句话说,媒体查询将在屏幕尺寸小于 1000px 时执行。相当于:
@media screen and ( max-width: 1000px ) { body { background-color: green; } }
无法同时匹配低宽和高宽所以我想:
@media screen and (max-width: 123px) and (min-width: 4321px) {
/* Never ever */
}