0
votes

I have a simple SCSS structure like the following:

nav.main {
    a.close {
        svg {
            fill: black;
        }
    }
}

I'm then wanting to change the fill property to black if the data theme attribute on nav.main is set to light.

I'm a big fan of nesting and keeping things 'compact' so ideally I'd want to do something like the below, but unfortunately through all my different combinations I can't work out if it's possible. Ideally I'd prefer not to have to type out a.close and svg and use the nesting.

I come up against this all the time and always have break out of the nest.

nav.main {
    a.close {
        svg {
            fill: black;
            @at-root [data-theme="light"]#{&} {
                // nav.main[data-theme="light"] a.close svg
                fill: white;
            }
        }
    }
}
2

2 Answers

0
votes

Oof, that @at-root line is hard to read.

You could try this:

a.close svg{
    nav.main &{
        fill: white;
    }
    nav.main[data-theme="light"] &{
        fill: black;
    }
}
0
votes

Short Answer

If you use an html element in the selector your SCSS pattern won't work. BUT if you remove it then it should work fine. The problem is that your compiled css isn't nav.main[data-theme="light"] a.close svg but [data-theme="light"]nav.main a.close svg.

I tried to explain that here. https://stackoverflow.com/a/73160384/2159402