Sass parent parent specific

I am writing CSS in BEM style and have this code:

.nav {
    &__list {
      &__item {
      }    
    }
  &__link {
    &--active { 
    }
  }
}

      

How do I get to .nav .nav__link--active

and .nav__link.nav__link--active

from the code above? How can I increase the specificity with this method?

0


source to share


1 answer


There is no magic method for this. Save the desired selector as a variable and socket as usual.



.nav {
  $sel: &;
    &__list {
      &__item {
        color: red;
        #{$sel} & {
          border: 1px solid;
        }
      }    
    }
  &__link {
    &--active {
      color: blue;
      #{$sel} & {
        border: 1px dashed;
      }
    }
  }
}

      

+3


source







All Articles