【发布时间】:2018-08-23 01:01:19
【问题描述】:
当我在父级中有悬停事件时,我对编写子级选择器有疑问。
说我有这样的 HTML,
<div class="root">
<div class="root__element">
<div class="root__sub-element" />
</div>
</div>
在 sass 中,
.root {
$root: &;
&__element {
&:hover {
#{$root}__sub-element {color: red;} // question comes here, why
// not using .root_sub-
// element?
}
}
}
我想要的是在root__element 中发生悬停事件,root__sub-element 中发生颜色变化。
我应该使用 & 来保留 SASS 还是直接使用 '.root__sub-element'?
【问题讨论】:
-
我为此做了mixin。这是我的另一个答案:stackoverflow.com/questions/9293891/…
-
$root = &;应该是$root : &; -
@Sachink 不错 :)
标签: sass css-selectors bem