Quantity Queries for CSS
alistapart.com
alistapart.com
It's sort of but not really "hackish" because he uses perfectly legitimate, if relatively obscure features of CSS, things we ought to know but haven't studied enough.
The result is an elegant approach to responsive design. Templates and other tools no doubt use such approaches under the hood. A few lines of CSS doing the job without having to drag along the bloat of a framework is a very good result.
Having the knowledge to directly apply CSS to achieve design goals is enormously powerful and worth learning about.
I'm really just repeating what was said by a Facebook developer (I've forgotten his name at this moment) - but I think it is worth being said: CSS is more a separation of technology, than a separation of concerns. It makes much more sense to have all your code (styles, scripts, markup) in one file for a specific module. Any repeated styles/scripts/markup can be imported as a module.
In hindsight, it makes me wonder what the hell I've been thinking all this time.
By saying "CSS is more a separation of technology, than a separation of concerns" you are saying "CSS is more a separation of concerns, than a separation of concerns" or possibly "CSS is more a separation of technology, than a separation of technology".
As for the modularity concept, that doesn't have to flout or adhere to "separation of concerns". That's just a different thing.
It's also rumored to be Turing complete and the W3C's CSS working group is the one that's slowing down the progress of CSS into a full blown scripting language for performance reasons (Fast vs Full debate)
However, this doesn't mean that you can't reinterpret "Separation of Concerns" or subscribe to this notion of "Separation of Technologies" and that modules should be self-sufficient.
You can say and do whatever you want but I'm sticking with placing all my style info in CSS files and exploring exhaustively all the possibilities this quirky language provides to manipulate the layout/formatting/styling aspects of my web apps/pages.
If you want to go with scripting you will end with your own ad-hoc incomplete bug-ridden slow implementation of half of CSS engine, to paraphrase famous law. Bugs will be prevasive, because your "solver script" will be good in most cases except some where it will be glitching or unstable.
You can take a look at QOCA layout constraint solving engine to get a feeling how much code you will write in the end.
I'm not putting this in my CSS just to satisfy some noble goal of "layout versus presentation":
li:nth-last-child(-n+6):first-child,
li:nth-last-child(-n+6):first-child ~ li {
/* properties here */
}
It's too cryptic. I feel another more important noble goal is to keep your CSS readable and understandable.Note that I'm not advocating blindly using "whatever has the nicest code", but in a lot of cases, a clean codebase is far better than 100% adherence to specs and guidelines. Write readable code first, optimize it later if you need to.
As for the ugliness of the CSS, well... that's what the CSS that works for the purpose looks like. Function over form. I'd recommend _adding a comment_ if you want developers to grok the code.
I must say I find it odd that you think transparency for fellow developers is _more_ important than the actual purpose of the code. Your convenience in maintaining the product cannot be more important than the product itself, surely?