What is the difference between “screen” and “only screen” in media queries?

后端 未结 5 1862
栀梦
栀梦 2020-11-22 14:33

What is the difference between screen and only screen in media queries?



        
5条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-22 15:26

    The answer by @hybrid is quite informative, except it doesn't explain the purpose as mentioned by @ashitaka "What if you use the Mobile First approach? So, we have the mobile CSS first and then use min-width to target larger sites. We shouldn't use the only keyword in that context, right? "

    Want to add in here that the purpose is simply to prevent non supporting browsers to use that Other device style as if it starts from "screen" without it will take it for a screen whereas if it starts from "only" style will be ignored.

    Answering to ashitaka consider this example

    
    
    

    If we don't use "only" it will still work as desktop-style will also be used striking android styles but with unnecessary overhead. In this case, IF a browser is non-supporting it will fallback to the second Style-sheet ignoring the first.

提交回复
热议问题