@media内置@media&糟糕的SASS解析

时间:2012-01-17 13:32:59

标签: css

我有以下sass:

.branded
  @media only screen and (-webkit-min-device-pixel-ratio: 2), only screen and (min-device-pixel-ratio: 2)
    @media screen and (orientation:portrait)
      background-image: url("../img/fbc/citroen_640x960.jpg")
    @media screen and (orientation:landscape)
      background-image: url("../img/fbc/citroen_960x640.jpg")
    background-size: 50%

并将其解析为以下CSS:

@media only screen and (-webkit-min-device-pixel-ratio: 2), only screen and (min-device-pixel-ratio: 2) {
    .branded {
        background-size: 50%;
    }
}

@media only screen and (-webkit-min-device-pixel-ratio: 2), only screen and (min-device-pixel-ratio: 2) and screen and (orientation:portrait) {
    .branded {
        background-image: url("../img/fbc/citroen_640x960.jpg");
    }
}

@media only screen and (-webkit-min-device-pixel-ratio: 2), only screen and (min-device-pixel-ratio: 2) and screen and (orientation:landscape) {
    .branded {
        background-image: url("../img/fbc/citroen_960x640.jpg");
    }
}

我发现它不起作用,我在这一行上收到错误:

@media only screen and (-webkit-min-device-pixel-ratio: 2), only screen and (min-device-pixel-ratio: 2) and screen and (orientation:landscape) {

为什么会这样,以及SASS解析器如何创建带有错误的CSS?这是我的错误还是SASSes?

1 个答案:

答案 0 :(得分:0)

我也不认为可以在标准CSS中混用@media,但nesting in SASS是可能的。

我可能错了,但我认为错误可能来自混合:@media only screen和(-webkit-min-device-pixel-ratio:2),only screen和(min- device-pixel-ratio:2)和screen以及(orientation:landscape)

试试这个?

.branded
  @media only screen
    @media (-webkit-min-device-pixel-ratio: 2), (min-device-pixel-ratio: 2)
      background-size: 50%
      @media (orientation:portrait)
        background: url("../img/fbc/citroen_640x960.jpg")
      @media (orientation:landscape)
        background: url("../img/fbc/citroen_960x640.jpg")