使用 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: }
非常感谢
最佳答案
你正在寻找@at-root
:
#example-id-1 {
background: blue;
@at-root #example-id-2 {
background: red;
@at-root #example-id-3 {
background: yellow;
}
}
}
请注意,这是 Sass 3.3 的一项功能。
关于css - 是否有将后代输出到根的 SASS 规则?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25827695/