What does the 'only screen' code mean in a css media query? [duplicate]

对着背影说爱祢 提交于 2020-05-17 06:58:11

问题


What does the 'only screen' code mean in a media query?

//See below the 'only screen' part of the code
@media only screen and (min-device-width: 320px)

I have used code that works without the 'only screen' part of the code. What does it do or how does it help?


回答1:


From https://www.w3schools.com/cssref/css3_pr_mediaquery.asp

only: The only keyword prevents older browsers that do not support media queries with media features from applying the specified styles. It has no effect on modern browsers.

The screen keyword references that it's a computer, mobile phone or tablet etc. There are two other media types, print and speech, as well as the default all.

Simply: The only keyword is optional and used for backwards compatibility. The screen keyword will default to all.




回答2:


@media only screen and (min-device-width: 320px)

As you said and it's true that code can run without only screen but when you use it that means you are only targeting screens like desktop, laptop, tablet, mobile etc. screen devices not other media devices like printing media and screen readers etc.

resource: https://www.w3.org/TR/CSS2/media.html



来源:https://stackoverflow.com/questions/56198043/what-does-the-only-screen-code-mean-in-a-css-media-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!