【发布时间】:2017-12-18 17:19:49
【问题描述】:
我想使用以下模式选择父级。
我知道我可以在父选择器中写这个,但我想知道是否可以在子选择器中为子选择器添加父伪类的前缀。
JSX:
<div class="parent">
<div class="child" />
</div>
<div class="parent">
<div class="child" />
</div>
SCSS:
.parent {
height: 100px;
.child {
// the goal is to write this so it produces the CSS output below, from
// within .child
&:first-child & {
height: 50px;
}
}
}
CSS [输出]:
.parent:first-child .child {
height: 50px;
}
【问题讨论】:
-
尽管找到了解决方案,但我仍然很想知道是否有办法在不重写子类中的父类名称的情况下做到这一点。