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

前端 未结 3 1111
抹茶落季
抹茶落季 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条回答
  • 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 ;)

    0 讨论(0)
  • 2021-02-02 14:59

    Only use this:

    @media(-webkit-min-device-pixel-ratio:0) {
    
    }
    
    0 讨论(0)
  • 2021-02-02 15:17

    Here is a quick workaround with YUI compressor's special comment.

    @media screen and/*!*/(-webkit-min-device-pixel-ratio:0) { ... }
    

    The issue is fixed in the current (2.4.5) version

    https://github.com/yui/yuicompressor/blob/master/src/com/yahoo/platform/yui/compressor/CssCompressor.java#L180

    0 讨论(0)
提交回复
热议问题