2016-01-21 67 views
-5

这是我的sass结构请解释一下它的意思?了解sass结构

实际上我正在分析一个代码结构。我无法低估结构。

.class-name{ 
    some styles.. 
    &.class-name2{ 
    some styles.. 
    } 
} 
+2

你在Google上搜索过吗?或者查阅[Sass的文档](http://sass-lang.com/guide)? – xaviert

+0

你不明白哪部分?你懂CSS吗?文档是一个很好的开始。您也可以运行sass任务并查看输出(css)。该代码显示'嵌套',并使用'引用父选择器&' – allcaps

+0

谢谢..当然,我需要深入到文档。 –

回答

2

&通知预处理器在嵌套类的前面添加父选择器。

所以这个:

.class-name{ 
     background: blue 
     &.class-name2{ 
      background: red; 
     } 
} 

将编译过:

.class-name {background: blue;} 
.class-name.class-name2 {background: red;} 

的用法是:

<div class="class-name">This background is blue</div> 

<div class="class-name class-name2">This background is red</div> 
+0

Woww ..真的很感谢你的回答.. !!! –