SASS 使用 & for parent,并且该父母是第一个孩子



我知道你可以使用&:

来指定元素是否有特定的父元素
.btn {
    .btn-group & {
        color: blue;
    }
}

但是你能不能也说一下,如果父结点是btn-group,而。btn-group是第一个子结点?

类似:

.btn {
    .btn-group & &:first-child {
        color: blue;
    }
}

我算出来我能做到:

.btn {
    .btn-group:first-child & {
        color: blue;
    }
}

但是找不到有多个伪选择器的方法(除了使用上面用逗号分隔的语法):

// This doesn't work :(
.btn {
    .btn-group & {
        &:first-child,
        &:last-child {
            color: blue;
        }
    }
}

最新更新