代码之家  ›  专栏  ›  技术社区  ›  I am me

是否有用于将后代输出到根的SASS规则?

  •  1
  • I am me  · 技术社区  · 10 年前

    使用SASS&Compass,您是否仍然可以以缩进的后代方式编写,但添加一个规则/命令,以便将给定的后代写入另一个级别(例如根)?

    因此:

    #example-id-1 {
        background: blue:
    
        #example-id-2 {
            background: red:
    
            #example-id-3 {
                background: yellow:
            }
    
        }
    
    }
    

    通常会输出以下内容:

    #example-id-1 { background: blue: }
    #example-id-1 #example-id-2 { background: red: }
    #example-id-1 #example-id-2 #example-id-3 { background: yellow: }
    

    但规则是否适用于 #example-id-2 #example-id-3 使得输出变为:

    #example-id-1 { background: blue: }
    #example-id-2 { background: red: }
    #example-id-3 { background: yellow: }
    

    非常感谢

    1 回复  |  直到 10 年前
        1
  •  2
  •   cimmanon    10 年前

    您正在查找 @at-root :

    #example-id-1 {
        background: blue;
    
        @at-root #example-id-2 {
            background: red;
    
            @at-root #example-id-3 {
                background: yellow;
            }
        }
    }
    

    注意,这是Sass 3.3的特性。