-1

My app.css contain this css variable which is used in my css header component and it works well.

:root {
  --fs-subtitle-spartan: 1rem;
}

The class that uses it in the header component :

.menu__items {
 font-size: var(--fs-subtitle-spartan);
}

But when I want to modify the variable in media queries of my header it doesn’t work.

@media (width < 48em) {
  :root {
    --fs-subtitle-spartan: 1.5rem;
  }

How can I change css variables in media queries of other components ?

It only works if I change the css variable in the media queries of my app.css.

0

1 Answer 1

1

Try @media (screen and max-width = 768px) instead of @media (width < 48em). This is because:

  • your media query's syntax wasn't correct
  • you should always use px values in media queries, never em, because px values are absolute.
Sign up to request clarification or add additional context in comments.

1 Comment

I use the level 4 specification of media queries as follows: developer.mozilla.org/en-US/docs/Web/CSS/Media_Queries/… The syntax works well in my app.css. I tried the basic syntax but it doesn’t work in the component header either. I use the em value for consistency in all browsers because safari does something different if you use rem or pixels compared to other browsers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.