Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


Chris Andruszko
Chris Andruszko
18,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?

1 Answer

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.

Chris Andruszko
Chris Andruszko
18,392 Points

The more I learn, the more I realize how much I don't know. I'll start digging into flexbox (as well as finish up the remaining CSS courses on here).

I know that flexbox is talked about in one course, and I know it's either a course from Guil Hernandez or Nick Pettit lol. You keep going through the CSS courses on here, and you'll run into it. Good luck, Chris!