W3 css 标准媒体查询的澄清 - “仅”
我想使用 media 属性链接到基于用户代理的不同 css 文件。我对如何使用关键字“only”感到困惑。 W3 网站指出“可选的“only”关键字可用于对旧版浏览器隐藏样式表。浏览器处理以“only”开头的媒体查询,就好像“only”关键字不存在一样。”这不是无言以对吗?我读它的意思是“如果存在关键字‘only’,旧版浏览器会忽略它。”那为什么要用它呢?我知道我在这里遗漏了一些重要信息。有人可以帮忙吗?
I want to use the media property to link to different css files based on the user agent. I am confused by how the keyword "only" is used. The W3 site states that "The optional “only” keyword can be used to hide the stylesheet from older browsers. The browsers process media queries starting with “only” as if the “only” keyword is not present." Isn't this a non-statement? I read it as saying "If the keyword 'only' is present, older browsers ignore it." Then why use it? I know I'm missing some vital info here. Can anyone help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
only 关键字对不支持媒体查询的旧版浏览器隐藏样式表。
其他信息可以在这里找到:https://developer.mozilla.org/en/CSS/Media_queries< /a>
The only keyword hides style sheets from older browsers that don't support media queries.
Additional information can be found here: https://developer.mozilla.org/en/CSS/Media_queries
是的。 “it”特指 CSS3 媒体查询(您将看到的大多数媒体查询),而不是早期有限/愚蠢的媒体查询。
为了避免浏览器检测和处理错误:至少这意味着错误控制台不会填充无关的消息,在许多情况下,它避免向用户呈现对话框和/或调试器窗口,有时甚至意味着浏览器不会在您的页面上“呕吐”,根本拒绝显示它。
Yep. "it" is specifically CSS3 media queries (most of those you will see), not the limited/stupid earlier media queries.
To avoid having the browser detect and process errors: at minimum this means the error console does not fill up with extraneous messages, in many cases it avoids presenting a dialog box and/or a debugger window to the user, and it sometimes even means the browser will not "barf" on your page refusing to show it at all.
*
和only *
等查询是相同的表示形式,因此兼容的浏览器通过从表示形式中删除only
关键字来正确解释它。旧版浏览器无法识别
only
,将其解释为未知媒体类型,将查询评估为false
,并忽略(跳过)样式表。Queries like
*
andonly *
are identical representations, so compliant browsers interpret theonly
keyword correctly by removing it from the representation.Older browsers don't recognize
only
, interpret it as an unknown media type, evaluate the query asfalse
, and ignore (skip) the stylesheet.