What's the semantic of “@media screen and (-webkit-min-device-pixel-ratio:0)”?

前端 未结 3 1112
抹茶落季
抹茶落季 2021-02-02 14:34

I happened to use the below CSS hack for WebKit-based browsers, according to http://www.webmonkey.com/2010/02/browser-specific_css_hacks/.

@media screen and (-we         


        
3条回答
  •  -上瘾入骨i
    2021-02-02 14:58

    The media query itself is, like you say, used to filter WebKit because it uses a -webkit- property.

    Chrome is simply a little strict when you say it can't recognize

    @media screen and(-webkit-min-device-pixel-ratio:0)
    

    because that is in fact invalid CSS. The space after the and keyword is significant. This is clearly stated in the CSS3 media query spec:

    EXAMPLE 20

    The following is an malformed media query because having no space between ‘and’ and the expression is not allowed. (That is reserved for the functional notation syntax.)

    @media all and(color) { … }
    

    The functional notation refers to things like url(), rgb() and rgba(). As you can see there is no space between the function name and the opening parenthesis in these examples.

    and is not a function, but simply a keyword to say that the media query must match the medium you specify, and that the layout engine must satisfy the expression you place after it. The parentheses around -webkit-min-device-pixel-ratio:0 simply denote it as an expression.

    Addendum: yes, that does mean your CSS optimizer has a bug ;)

提交回复
热议问题