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

can't handle nested media rules? #7

Open
pkyeck opened this issue Sep 10, 2014 · 1 comment
Open

can't handle nested media rules? #7

pkyeck opened this issue Sep 10, 2014 · 1 comment

Comments

@pkyeck
Copy link

pkyeck commented Sep 10, 2014

I have something like this

@media only screen and (max-width: 940px) {
  .test {
    background-color: red;
  }

  @media (min-resolution: 144dpi) {
    .test {
      background-color: green;
    }
  }
}

@media (min-resolution: 144dpi) {
  .test {
    background-color: yellow;
  }
}

but this gets converted to

@media (min-resolution: 144dpi) {
  .test {
    background-color: yellow;
  }
}

@media only screen and (max-width: 940px) {
  .test {
    background-color: red;
  }
}

so I'll lose my nested media rules :(

@pkyeck pkyeck changed the title can't handle nested media-queries? can't handle nested media rules? Sep 10, 2014
@fesor
Copy link

fesor commented Nov 28, 2014

CSS doesn't allow to use nested media queries. You should use and operator. Also you may want to use CSS preprocessors like LESS or SASS:

@media only screen and (max-width: 940px) {
  .test {
    background-color: red;
  }

  @media (min-resolution: 144dpi) {
    .test {
      background-color: green;
    }
  }
}

@media (min-resolution: 144dpi) {
  .test {
    background-color: yellow;
  }
}

Less will compile it to

@media only screen and (max-width: 940px) {
  .test {
    background-color: red;
  }
}
@media only screen and (max-width: 940px) and (min-resolution: 144dpi) {
  .test {
    background-color: green;
  }
}
@media (min-resolution: 144dpi) {
  .test {
    background-color: yellow;
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants