While i was trying BEM and SCSS. Using SCSS to select modifier and Elements is easy but the hard part is while using modifier and referencing element that doesn't have modifier class is breaking the neat approach i made. Here is the quick example what i am trying to do.
This is the HTML
<div class="icon-box icon-box--red">
<h3 class="icon-box__title>This is title</h3>
</div>
And the SCSS
.icon-box {
&__title {
color: black;
}
&--red {
&__title {
color: red;
}
}
}
And the output css is
.icon-box {
background: white;
}
.icon-box__title {
color: black;
}
.icon-box--red {
background: black;
}
.icon-box--red__title {
color: red;
}
The compiled CSS is correct but i want to achieve this
.icon-box {
background: white;
}
.icon-box__title {
color: black;
}
.icon-box--red {
background: black;
}
.icon-box--red .icon-box__title {
color: red;
}
While i can reference it using name .icon-box__title but i want to go back to grand parent. Is there any approach i can use?
Thank you