I often nest SCSS and I know how to target the parent element using &
, but in this particular case, it's causing me some trouble! I have a feeling I'm missing something obvious here, but I just can't seem to get it right. Here is my (simplified) SCSS code:
[class^="icon--"]:before,
[class*=" icon--"]:before {
opacity: .50;
}
Basically, I am using an icon font and I want the icons (added using the :before element) to appear lighter than the text they are attached to - which is okay.
Now, I want to override this on certain elements where this class is applied. I have tried the following (below), which does remove the opacity from the targeted element...but it also seems to cancel out the opacity: .50;
on every element. So essentially, everything has opacity: 1;
set.
[class^="icon--"]:before,
[class*=" icon--"]:before {
opacity: .50;
@at-root {
.btn#{&} {
opacity: 1;
}
}
}
Any suggestions?