-
Notifications
You must be signed in to change notification settings - Fork 3.4k
@media queries should behave like nested rules #152
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
Comments
I'm not sure I follow, you can specify attributes directly:
results in in the exact same CSS. Regarding your 2nd point, you aren't supposed to put @media queries inside other elements, because it would lead to invalid css, ie:
would result in:
which is invalid. |
When using @media queries, you could NOT normally write this (because there is no selector):
Instead, you would have to write:
What I'm calling for is that LESS.js be smart about how it handles @media queries. Following the normal rules, yes, this would result in invalid syntax:
But what I'm suggesting is that LESS.js know to handle @media queries differently from other selectors so that the above would actually compile as:
This would make @media queries much easier to work with. At the moment, they conflict with LESS's principle of nested selectors, but this new behavior would be revolutionary in terms of making fluid layouts really easy to create. |
Sass does it this way, and it works pretty well. |
gotcha, will look into it. |
Yes, SASS does this and it's fantastic. |
Consider this another "me too" on this one. SASS calls it "@media Bubbling." Here's the case I'm thinking of:
Obviously, that produces:
But if I want to change the font size of .selector p when we reach a particular width, I currently do:
This produces a lot of repeated CSS and puts selectors in different parts of the document and is, in general, not very DRY. It's a maintenance headache waiting to happen. What I'd like to be able to do is this:
It's similar to using "&" combinator in a nested rule. Both of the last two code blocks would compile to:
|
this is implemented in less now I believe. |
I've been working closely with @media queries for a new version of the 1KB CSS Grid that will be written in LESS.js, but I have noticed two crucial inconsistencies in how @media queries are currently being handled:
You shouldn't need to define a selector within a media query, but should be able to specify CSS attributes directly. For instance:
Secondly, @media queries in LESS.js should be aware of their position within other nested rules. For example:
Should result in:
But unfortunately, it currently results in:
I am more than happy to be a champion for @media query support in LESS, so please let me know if there's anything else I can do to help!
The text was updated successfully, but these errors were encountered: