css – 是否有一个SASS规则用于输出后代到根?

前端之家收集整理的这篇文章主要介绍了css – 是否有一个SASS规则用于输出后代到根?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
使用SASS&指南针,你仍然可以用缩进的后代方式编写,但是添加一个规则/命令,以便将给定的后代写入另一个级别,例如根?

所以这:

#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: }

非常感谢

解决方法

你在寻找@ at-root:
#example-id-1 {
    background: blue;

    @at-root #example-id-2 {
        background: red;

        @at-root #example-id-3 {
            background: yellow;
        }
    }
}

请注意,这是Sass 3.3功能.

原文链接:https://www.f2er.com/css/217705.html

猜你在找的CSS相关文章