首页 > 解决方案 > 有没有办法在没有变量的情况下在 sass 中获得祖父母的名字?

问题描述

带变量

.comment {
    $hah: ".comment";
    &__item {
        &:hover #{$hah}__right > #{$hah}__bottom {
            height: 3rem;
        }
    }
}

我可以在没有变量的情况下获得祖父母的名字吗?

.comment {            this              this
        &__item {      vv                vv
            &:hover .comment__right > .comment__bottom {
                height: 3rem;
            }
        }
    }

所以我不必在里面再写 .comment 类

标签: sass

解决方案


SASS 中没有祖父选择器,但是,如果您不想.comment再次编写选择器,可以将 & 符号存储在变量中:

.comment {
    $hah: &;
    &__item {
        &:hover #{$hah}__right > #{$hah}__bottom {
            height: 3rem;
        }
    }
}

这是一篇关于这个的好文章


推荐阅读