I have the following CSS:
.PageA, .PageB, .PageC {
#parentDiv {
/*some css*/
}
.plantTest {
&.color {
/*some css*/
.row {
/*some css*/
p {
/*some css*/
}
}
}
}
.oceanTest {
.depth {
h2 {
/*some css*/
}
}
}
#theContent {
/*some css*/
}
}
My question is, lets say I want PageA
to get all of the CSS, but for PageB
and PageC
I only want to target the css that is in #theContent
and ignore the CSS in #parentDiv
, plantTest
oceanTest
.
The easy solution is to create separately CSS for PageB
and PageC
and target #theContent
, but this would be repeated CSS code. So I am wondering is it possible to target only a part of a nested CSS?
2
Answers
Give both of them a common class, and then write variations within .PageX scopes.
Also, sass parent selector could handy to write the code more easily:
https://sass-lang.com/documentation/style-rules/parent-selector/
We have:
.PageB
,.PageC
: share with.PageA
styles with#theContent
.PageA
: everything else + all from "1" (@extend .PageB;
)As I see the solution: