CSS Tutorial – Nested Media Queries


Rengga Dev – We don’t have “regular” nesting in CSS. Maybe this becomes a thing someday, or something like it. That would be cool, although that pre-spec doesn’t mention anything about media queries. I’d hope we get that right out of the gate if we ever do get native CSS nesting. In fact, I’d trade it for selector nesting in a heartbeat. I’d say that’s the most useful thing a CSS preprocessor like Sass does today.

But I’ve digressed before I even began. You can nest media queries in native CSS, as long as you’re doing it from the root. It’s funny to see in native CSS, but it works!

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
@media screen {
@media (min-width: 1px) {
@media (min-height: 1px) {
@media (max-width: 9999px) {
@media (max-height: 9999px) {
body {
background: red;
}
}
}
}
}
}
@media screen { @media (min-width: 1px) { @media (min-height: 1px) { @media (max-width: 9999px) { @media (max-height: 9999px) { body { background: red; } } } } } }
@media screen {
  @media (min-width: 1px) {
    @media (min-height: 1px) {
      @media (max-width: 9999px) {
        @media (max-height: 9999px) {
          body {
            background: red;
          }
        }
      }
    }
  }
}
Nandemo Webtools

Leave a Reply