I have a SCSS compiler question for ye!
I'm currently refactoring my first project to use SCSS (and a more structured stylesheet filing system, i.e. split in partials, modules etc.) to get to learn more about the SCSS approach, but I've encountered an issue with the compiler which is driving me stark ravin mad.
Here's a sample of code that gets messed up by the compiler:
#navBar {
.desktopMenu {
.dropdownExcluder {
display: none;
}
}
}
The above code tells the browser not to display the html element I created to be the display for desktop view. Then using a media query I set the display to flex for that given element at >=620px:
@media screen and (min-width: 620px) {
#navBar {
.desktopMenu {
.dropdownExcluder {
display: flex;
}
}
}
}
In both examples I've used nesting to nest a class within a class within an ID selector. But with the second example the code is then nested again within the media query. The problem with the compiler is that the first example is rendered into CSS as:
#navBar .dropdownExcluder .desktopMenu {
display: none;
}
and the second example is rendered into CSS as :
@media screen and (min-width: 620px) {
#navBar .desktopMenu {
display: flex;
}
}
So as you will see the compiler has excluded (for the media query) the .dropdownExcluder class from the selector. What it should read is:
@media screen and (min-width: 620px) {
#navBar .dropdownExcluder .desktopMenu {
display: flex;
}
}
The problem with the compiler working this way is that because the specificity of the selector within the media query is reduced (the specifity is rendered less specific than that of the same selector outside of the media query) then despite the media query the original selector overrides the code with the media query and even though I can see the display: flex has been set in the browser it is overridden by display:none from the original selector.
Has anyone experience issues like this before? This stackoverflow question helped my figure out the specificity issue Media Query Styles Not Overriding Original Styles but is there a way to force the compiler for 'strict compilation' or am I just making up terms?