M
M
movsumlu2022-02-28 21:13:52
css
movsumlu, 2022-02-28 21:13:52

[SASS] why are breakpoints not firing in media-queries?

Hello everyone, I ran into such a problem that I import sass variables into components, the colors in the variables are applied correctly, and the variables in the media do not work, I don’t understand what’s the matter (if you manually write media (max-width: 550px) - everything works ):

// variables.scss
:root {
  --small-screen: 520px;
  --text-color: #b1bdb4;
}

// app.scss
@media (max-width: var(--small-screen)) {
  .sidebar {...}
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey delphinpro, 2022-02-28
@movsumlu

Custom properties do not work in media query expressions. Yes, and in any other.
They can only be used as the value of an element property (selector).
To contemplation. How should the following code behave:

:root {
  --small-screen: 500px;
}
.sidebar { background: red; }

@media (max-width: var(--small-screen)) {
  :root {
    --small-screen: 1000px;
  }
  .sidebar { background: green; }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question