我想使用以下模式选择父级。
我知道我可以在父选择器中写这个,但我想知道是否可以在子选择器中将父类的伪类作为子类的前缀。
JSX:
<div class="parent">
<div class="child" />
</div>
<div class="parent">
<div class="child" />
</div>
Run Code Online (Sandbox Code Playgroud)
社会保障:
.parent {
height: 100px;
.child {
// the goal is to write this so it produces the CSS output below, from
// within .child
&:first-child & {
height: 50px;
}
}
}
Run Code Online (Sandbox Code Playgroud)
CSS [输出]:
.parent:first-child .child {
height: 50px;
}
Run Code Online (Sandbox Code Playgroud)