Hacker News new | ask | show | jobs
by kronholm 4894 days ago
I've only ever done responsive via JavaScript, as I often need to target as many old and new browsers as possible. It seems like my method is way easier and faster than this "new" fancy CSS way. Does anyone have any experiences with both approaches, and if yes, which do you prefer?

For those wondering: My method is pretty simple - I use a global ratio which is multiplied with width/heights, and a resize() function, which is called when the page is loaded and resized.

Edit: Long timer HN lurker, registered to post this. Also forgot to say I enjoyed the article, thanks!

3 comments

The biggest reason I like using pure CSS for this is because it separates the display code and functionality code more clearly. Granted, you can and should be doing that with your JS anyway, but the boundaries are clearer if you keep it to CSS and you're less inclined to take shortcuts and start writing complex or hard-to-understand JS.
I tend to use CSS for the bulk of layout. Lately leaning on say Twitter Bootstrap as a base... and using JS for some tweening, or other points. I also use Modernizr, and other JS to enhance classes in the HTML element for CSS use. I find this works pretty well... I can keep my rules in CSS, but can enhance them via JS. My enhancers are the only script I put into the HEAD (before the CSS), all other scripts are just before the closing BODY element with ads and analytics last of the scripts. I do think that having a good base CSS knowledge is important.

The exception to this, would be a full-screen site/application where you are using the full field of view for an interactive display, or simulation. Then JS leaning and even canvas are more important for interaction.

I'd be interested to see this idea in action - got any sites up as examples?
I think this one can be very useful for examples: http://responsivedeck.com
Sadly no, nothing I can show yet :(