Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
Chris Andruszko18,392 Points
reordering layouts in media queries using JS...
http://codepen.io/sketchcrush/pen/OPxoZQ (For some reason, CodePen is displaying the divs weird in the media query. But you'll at least get the idea of what I'm trying to do.)
I've created four divs, all of them are labeled. You'll notice the divs are not in sequence in the HTML (their current order is .box_1, .box_4, .box_2, .box_3). When I decrease the display resolution and the media query kicks in, they remain in that order as expected. However, when they're displayed in the media query, I want to reorder the boxes so that they're in sequential order.
I've read a few methods on how to do this, but I'm just a bit confused at this point. I suppose I could append the divs somehow with jQuery. But it could also be done with enquire.js. I'm having trouble finding (and understanding) the best solution. Can anybody give me some advice on how to do this?
Hey Chris Andruszko,
Have you thought about doing a flexbox layout? It is one of those layouts that can be done all in CSS, and this guide from CSS Tricks is completely awesome. Flexbox has support from all major desktop browsers (even IE 11 surprisingly) including almost all of the major mobile browsers (except for Opera Mini). I got that data from this caniuse link. Flexbox makes it super simple to change the sort order. You'll love it.