Smashing Magazine recently tweeted about two Blog articles: Responsive Containers by Andy Hume and Media Queries Are A Hack by Ian Storm Taylor basically arguing that media queries are not enough, we need “element queries”. Fortunately, our friend François REMY had proposed something like this to the CSS Working Group and based on some work with Mozilla’s Daniel Buchner has created a prollyfill with HitchJS to let you use them now, fork it, provide feedback and help make the Web a better place for us all.
Download the latest version of HitchJS, mark one of your stylesheets with the data-hitch-interpret flag, require it and get rolling:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!doctype html> | |
| <html> | |
| <head> | |
| <title>Min-width/Max-with prollyfill in JS</title> | |
| <!– link up the latest hitchjs –> | |
| <script src="http://hitchjs.com/dist/hitch-0.6.3.min.js"></script> | |
| <!– mark a style or link tag with the data-hitch-interpret flag –> | |
| <style data-hitch-interpret> | |
| /* require his prollyfill (you could also get it from rawgithub mentioned in prose below) … */ | |
| @-hitch-requires http://www.hitchjs.com/use/fremycompany.minwidth/1; | |
| /* start using it… */ | |
| #inner:-js-min-width(600px) { | |
| background-color: green; | |
| } | |
| #inner:-js-max-width(600px) { | |
| background-color: yellow; | |
| } | |
| </style> | |
| …. | |
| </html> |
For a quick look at the basic proposal, see the draft in the HitchJS Repo – for a more in-depth look, check out his article on Element Query prollyfilling/concepts.