小编Sim*_*Phy的帖子

如何使用scss从子项中选择父伪类

我想使用以下模式选择父级。

我知道我可以在父选择器中写这个,但我想知道是否可以在子选择器中将父类的伪类作为子类的前缀。

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)

css sass ampersand

4
推荐指数
2
解决办法
2万
查看次数

标签 统计

ampersand ×1

css ×1

sass ×1