【问题标题】:SASS with BEM hover state [duplicate]具有 BEM 悬停状态的 SASS [重复]
【发布时间】:2020-11-23 08:10:12
【问题描述】:
    .card {
      &__header {}

      &__title {}

      &__content {}

      &__hasFullImage {

        &:hover {
          &__header {}

          //I want something like this
          .card__header {}

          //and not to type the parent class
        }
      }
    }

所以我面临着将 BEM 与 SASS 一起使用的情况,对我来说,这一切的重点是我可以将我的 SCSS 文件抓取到其他项目中,将父类的名称更改为我想要的任何内容并且可以使用。但是在悬停的这种情况下,如果不使用 &__header,我就无法到达 .card__header,所以如果我更改父类,我也需要更改悬停时的类。 因为输出将是 .card__hasFullImage .card__hasFullImage__header 而我想要的是 .card__hasFullImage .card__header。 有什么方法可以在不输入父类的情况下做到这一点?

【问题讨论】:

    标签: css class sass hover bem


    【解决方案1】:
    .card {
      $this: &;
      
     &__hasFullImage {
       &:hover {
          #{$this}__header {}
        }
    }
    

    SCSS target class before :hover - 我也有同样的问题

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-16
    • 2013-06-19
    • 1970-01-01
    • 2013-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-04
    相关资源
    最近更新 更多