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

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

所以这:

  1. #example-id-1 {
  2. background: blue:
  3.  
  4. #example-id-2 {
  5. background: red:
  6.  
  7. #example-id-3 {
  8. background: yellow:
  9. }
  10.  
  11. }
  12.  
  13. }

通常输出这个:

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

但是规则可以应用于#example-id-2或#example-id-3,以便输出变为:

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

非常感谢

解决方法

你在寻找@ at-root:
  1. #example-id-1 {
  2. background: blue;
  3.  
  4. @at-root #example-id-2 {
  5. background: red;
  6.  
  7. @at-root #example-id-3 {
  8. background: yellow;
  9. }
  10. }
  11. }

请注意,这是Sass 3.3功能.

猜你在找的CSS相关文章