.header { color: black;
.navigation { font-size: 12px;
&.class { text-decoration: none }
}
}
Run Code Online (Sandbox Code Playgroud)
这会导致&用父选择器替换它并导致实际选择器与父选择器的连接:.header .navigation.class而不是正常的追加,这将导致.class成为一个后代:.header .navigation .class.
现在还有可能是以下内容(另见此处):
.header { color: black;
.navigation { font-size: 12px;
#some-id & .foo { text-decoration: none }
}
}
Run Code Online (Sandbox Code Playgroud)
这会产生以下结果:#some-id .header .navigation .foo 试试这里.该substition发生,我已经预先考虑选择(#some-id),以我的父母选择.
除了我永远不会以这种方式编码的事实,因为这可能会在很短的时间内弄乱你的样式表,我的问题是:
由于没有记录此功能,它是一个功能还是更可能是一个错误?
哪些是可能的副作用?
这个少:
.parent {
.child {
h1& {
color: red;
}
}
}
Run Code Online (Sandbox Code Playgroud)
编译为:
h1.parent .child {color:red};
我需要的是:
.parent h1.child {color:red};
建议表示赞赏。
我的问题类似于问题Less Immediate Parent Selector但不完全相同。因为选择器是由元素和类名组成的。问题是如何在不影响根选择器的情况下用其元素限定类名。