I'm currently adding a dark mode to a site of mine. The change is all handled via a script and takes into account the users preference and also the current appearance of their machine. I basically end up with a 'dark' class on <body>
if in dark mode otherwise nothing.
Everything is working perfectly but on one element I need to change the background image based on this but i'm encountering a problem because my top level selector is already based on body.
Here's my code:
.page-home {
.home-intro__caricature {
@include ratio-box(100%);
width: 100%;
border-radius: 50%;
background-color: var(--main-background-color);
background-image: url('../src/svgs/caricature.svg'), url('../src/svgs/pattern-light.svg');
background-repeat: no-repeat, repeat;
background-position: center bottom, center center;
background-size: contain, auto;
transform: rotateY(0deg);
z-index: 2;
transition: box-shadow 0.2s ease-in-out;
&.dark {
background-image: url('../src/svgs/caricature.svg'), url('../src/svgs/pattern-dark.svg');
background-repeat: no-repeat, repeat;
background-position: center bottom, center center;
background-size: contain, auto;
}
}
}
The issue is that .page-home
is a class on <body>
and .dark
also needs to be so. How can I construct the selector so that .dark
is added onto the selector for body
?