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

CSS

Is Flexbox meant to replace the media query method for response design?

I've googled this question but can't seem to find a direct answer. It seem as though this and the media query method do some what of the same thing.

1 Answer

Máté Végh
Máté Végh
25,607 Points

Hi Yusef,

I don't know what you mean exactly by replacing, but:

  1. Flexbox can't do the exact same things that media queries can and it's also true vice versa, therefore it's not meant to replace media queries.
  2. There are some cases however, where you can skip using media queries because of the abilities of flexbox. For example you can create responsive grids without media queries (I assume you meant this rather than replacing media queries entirely).

I see many advantages of using flexbox instead of media queries, but I see two main issues with this method:

  • Browser support – media queries have much larger support than flexbox
  • Items on the last line flexing full width instead of having a consistent width like the other items. Here's what I mean: http://codepen.io/mattvegetable/pen/QEqBkG

I see, I'm a little confused as to why flexbox is necessary. I did how watch another video here on treehouse where they indirectly said flexbox is a better method to using floats. Is that the point of flexbox?

Máté Végh
Máté Végh
25,607 Points

Sorry, I just realized I may have overcomplicated your question a bit :)

While the floated layout method is a hacky, not so elegant solution, flexbox doesn't require any clearfix hack or such workaround. But that's just one of the many benefits of flexbox.

Here are some more:

  • Flexbox has lots of features that let's you do things that you couldn't accomplish without ugly workarounds in CSS or without involving JavaScript. For example: flex-direction, align-items, order, etc.
  • With flexbox you can get the same result as with other methods by writing less code.
  • Flexbox is very easy to use once you get used to it. (It's almost addictive so you need to be careful to not overuse it.)

There are many great articles about flexbox out there, but this one is one of the most popular ones. You should definitely read through if you haven't already: https://css-tricks.com/snippets/css/a-guide-to-flexbox

Perfect, I just finished the flexbox course and it amazing. Just wish it worked for some of the older IE browsers

Máté Végh
Máté Végh
25,607 Points

I know, it's a big pain. You should definitely create fallbacks or not use flexbox at all if you want to optimize a website for older versions of IE. Also IE 10 and 11 are just partially supporting it, which means that it often produces very weird bugs. It can cause issues even in browsers that fully supports flexbox, so you really need to be careful.