V
V
Vadim Stepanenko2022-03-17 16:47:14
Sass
Vadim Stepanenko, 2022-03-17 16:47:14

Is it possible in scss to apply styles depending on the parent attribute?

Hey! My site theme (dark/light) is set in the attribute of the body tag theme="light/dark".

scss has this construct for media queries:

.element {
   ...

   @ media screen and (min-width: 544px) {
      // стили для экрана от 544 пкс
   }
}


Tell me, is there a design that will also allow you to set styles for an element, depending on the body attribute? Something like
.element {
   color: var(--color);

   @ body[theme="dark"] {
      --color: white;
   }

   @ body[theme="light"] {
      --color: #333333;
   }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey delphinpro, 2022-03-17
@Vadim1899

So write it down

.element {
   color: var(--color);

   body[theme="dark"] & {
      --color: white;
   }

   body[theme="light"] & {
      --color: #333333;
   }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question