css - @media 里面的 @media 和糟糕的 SASS 解析

标签 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?是我的错还是SASS?

最佳答案

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

我可能错了,但我认为错误可能来自混合:@media only screen and (-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")

关于css - @media 里面的 @media 和糟糕的 SASS 解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8895490/

相关文章:

html - 保存富字段后,Microsoft Sharepoint 将 "External Class"添加到我的 CSS

html - 'width' 是否适用于文本区域?

jquery - 在移动 View 中,我们希望显示每个 div 的 div 底部

html - 如何设置 DIV 的宽度以匹配其内容

html - 防止 HTML 表格调整大小溢出

javascript - 在 [Timestamp_1, Timestamp_2] 期间将对象从 Position_1 移动到 Position_2

html - ionic 选项按钮中的按钮,但我希​​望它垂直对齐

javascript - 如何在URL中使用 anchor 标记?

html - 使用浏览器的主滚动条滚动特定的 DIV 内容

值为空时 Chrome 中的 HTML 输入光标位置问题