-
Notifications
You must be signed in to change notification settings - Fork 69
Combine multiple 'matching' nested media queries #196
Comments
I thought about this when I implemented the nested media query feature. The problem is that LESS would have to change the order of CSS rules - which I deemed more important than the bloat that is generated otherwise.
The current implementation generates
If LESS would combine the media-queries it would be something like:
Since CSS rules order matters I decided not to put any effort in how to combine the media-queries (or rules all together) any further. Indeed, the generated LESS file contains bloat, but it doesn't surprise you with magic, which make things hard to debug / to express. If you want to avoid the bloat, restructure your LESS file. If you want to reduce the impact of the bloat, use gzipped css files (which should really crush these duplications) |
Correct. CSS order is quite important and merging alters that. |
I have only been using less in quite a basic implementation, but I have also run into this. Would it be possible to use functions in any advanced manner to be able to pass in rules and define where they get output? Rough idea that I appreciate won't actually work as is: li { // might make more sense .480({width:100px}) } |
I always use variables for media queries.
I know this won't work with nested properties, but I also don't think it is a good idea to use them, you lose the overview completely. |
We have attempted to do something about this using Grunt: |
Isn't CSS order a non-issue if you are properly using specificity and keeping your styles modular? Other than nomralize of course. |
Did you mean to comment on the obsolete ruby repo? |
There is a native LESS way to combine media queries with mixins. |
@godban There're more advanced (and more crazy) methods (see for example 1, 2), but all such tricks are sort of useless now because indeed there's stuff like group-css-media-queries and similar plugins/tools. Also notice this repo is absolete. |
Closing as moved to less/less.js#950. |
Currently this code:
...will output as:
..the media query '@media (min-width: 768px)' is duplicated creating bloat. Is there a way to get LESS to combine matching queries so it is output as:
The text was updated successfully, but these errors were encountered: