question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

change variable values in @media queries

See original GitHub issue

I would like to change variable value in media query and have automatically generated css where that variable was used.

I’m currently using variable to determine width of the sidebar:

LEFT_SIDEBAR = 200px;

Then using it as:

.sidebar
  width: LEFT_SIDEBAR

.content
  left: LEFT_SIDEBAR

But when I try to change variable value in media query it generates nothing:

@media screen and (max-width: 1000px)
  LEFT_SIDEBAR = 150px;

What I would expect is to see this:

.sidebar {
  width: 200px;
}
.content {
  left: 200px;
}
@media screen and (max-width: 1000px) {
  .sidebar {
    width: 150px;
  }
  .content {
    left: 150px;
  }
}

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:6
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
kolesnikova-tavicommented, Aug 1, 2016

I do something like that:

$media_mobile_landscape = 480px
$media_mobile = 320px

mobile()
  @media screen and (max-width: $media_mobile)
    {block}

mobile_landscape()
  @media screen and (max-width: $media_mobile_landscape)
    {block}

only_mobile_landscape()
  @media screen and (min-width: $media_mobile + 1px) and (max-width: $media_mobile_landscape)
    {block}

And then

+mobile()
    body
        background #f00

+only_mobile_landscape()
    body
        background #00f
1reaction
mynameistechnocommented, Jul 24, 2019

This would be awesome for use with dark mode, e.g.

@media (prefers-color-scheme: dark) {
  $background-color = black;
  $text-color = white;
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

CSS Using Variables in Media Queries - W3Schools
Now we want to change a variable value inside a media query. Tip: Media Queries are about defining different style rules for different...
Read more >
Changing variable value based on media query - Stack Overflow
Considering the variable is designed to change, it makes no sense to give it different values in different scenarios (such as media queries) ......
Read more >
Basic CSS: Use a Media query to change a variable
Basic CSS: Use a Media query to change a variable ... All you have to do is put the --penguin-size value and the...
Read more >
Using CSS Media Queries and Variables for Responsiveness
"In this article, we'll learn how to make responsiveness for manageable using CSS Media queries and Variables."
Read more >
Want CSS variables in media query declarations? Try this!
The first is what I'd recommend to existing Sass users: fall back to Sass variables for media queries, and use CSS variables everywhere...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found