sass - 有没有办法在没有变量的情况下在 sass 中获取祖 parent 姓名?

标签 sass

带变量

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

我可以得到没有变量的祖 parent 姓名吗?

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

所以我不必在其中再次编写.comment类

最佳答案

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

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

这是一个nice article关于这个。

关于sass - 有没有办法在没有变量的情况下在 sass 中获取祖 parent 姓名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55448369/

相关文章:

css - SCSS - nth-child(2) 影响所有后代

css - Susy 列布局重新排序

css - 整页部分 CSS

css - 使用 LESS 和 SASS 的性能

css - 在 SASS/SCSS 中定义变量覆盖

sass - 限制变量范围而不嵌套到子类或混入中?

html - 如何在不使用背景图像的情况下获得背景磨砂玻璃效果

vue.js - 错误 : Undefined variable in VueJS

sass - 如何获取网格断点变量的值

css - SASS/Stylus - 动态定义列表