Reputation: 75820
I'm attempting to style different code
blocks depending on which tag they are present in:
code
blocks that are inside a pre
tag, andcode
blocks that are NOT inside a pre
tagI know that I can just use the :not
selector in plain css:
pre > code {
color: red;
}
:not(pre) > code {
color: blue;
}
But using it in sass throws an error and fails to compile:
:not(pre) > code
color: blue
Error:
Generating development JavaScript bundle failed
^
Invalid CSS after "...size: 1.5rem; }": expected 1 selector or at-rule, was "not(pre) : {"
in /Users/Psy/my-app/src/styles/v3/base.sass (line 111, column 23)
File: src/styles/v3/base.sass
failed Re-building development bundle - 0.339s
What is the correct way to do the same in Sass?
To be clear: I'm not looking for other ways for "reorganizing" my Sass code. Instead, looking for an explicit selector where a tag is not inside another tag.
Upvotes: 1
Views: 274
Reputation: 75820
Okay, I probably should've done this sooner, but I searched Github to see how other sass projects do the same.
Looks like while the :not
selector works in SCSS the same way it works in CSS, we need to prefix the :not
selector with *
for SASS files:
*:not(pre) > code
color: blue
This works without errors.
Upvotes: 2
Reputation: 27491
You don't have to use :not
selector. You can simply style the code
and code
under pre
tag. This will provide the intended result:
code {
color: blue;
}
pre > code {
color: red;
}
Upvotes: 1