简体   繁体   中英

Classbuilding with scss (double ampersand)

I want to get the following selector B__E.B__E--M so that B__E--M only applies if the element also has the B__E class;

I have the following:

.B {
    &__E {
        // default color
        &--M {
            // Color i want
        }
    }
}

The problem is, that the --M modifier should apply another color, but doesn't overwrite the default color from the __E element.

This is not allowed:

.B {
    &__E {
        // default color
    }
}

.B__E.B__E--M {
    // color i want
}

If nothing is possible, this would be my guess:

.B {
    &__E {
        // default color
        &.B__E--M {
            // Color i want
        }
    }
}

You are looking for the double ampersand selector.

.B {
    &__E {
        color:black;
        &#{&}--M{
          color:white;
        }
    }
}

/* // Outputs:
  .B__E {
    color: black;
  }
  .B__E.B__E--M {
    color: white;
  }
*/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM