Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A nested @media query can cause an outer query to be split unnecessarily #1402

Closed
yukulele opened this issue Jul 18, 2021 · 2 comments
Closed
Labels
bug cosmetic Doesn't affects CSS semantics

Comments

@yukulele
Copy link

If @media is nested in another @media, next @media are repeated.

Example:

input:

@media (min-width: 500px) {
    body{
        color: black;
        main{
            color:grey;
            @media (max-width: 1000px) {
                color: green;
            }
        }
        h1{
            color: red;
        }
        h2{
            color: blue;
        }
    }
}

output:

@media (min-width: 500px) {
  body {
    color: black;
  }
  body main {
    color: grey;
  }
}
@media (min-width: 500px) and (max-width: 1000px) {
  body main {
    color: green;
  }
}
@media (min-width: 500px) {
  body h1 {
    color: red;
  }
}
@media (min-width: 500px) {
  body h2 {
    color: blue;
  }
}

expected:

@media (min-width: 500px) {
  body {
    color: black;
  }
  body main {
    color: grey;
  }
}
@media (min-width: 500px) and (max-width: 1000px) {
  body main {
    color: green;
  }
}
@media (min-width: 500px) {
  body h1 {
    color: red;
  }
  body h2 {
    color: blue;
  }
}
@jathak jathak added the cosmetic Doesn't affects CSS semantics label Jul 20, 2021
@jathak
Copy link
Member

jathak commented Jul 20, 2021

The actual and expected output here should be equivalent as far as semantics go. Combining the two rules into one media query is probably more ideal, but making this cleaner is not something we're likely to have the bandwidth for.

If you really want to avoid these duplicate media queries, you could instead just move the nested query to the end of the outer one.

@nex3 nex3 added the bug label Aug 4, 2021
@nex3 nex3 changed the title repeated @media A nested @media query can cause an outer query to be split unnecessarily Jun 15, 2022
@nex3
Copy link
Contributor

nex3 commented Jun 15, 2022

Duplicate of #777.

@nex3 nex3 closed this as not planned Won't fix, can't repro, duplicate, stale Jun 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug cosmetic Doesn't affects CSS semantics
Projects
None yet
Development

No branches or pull requests

3 participants