treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Where to put CSS3 Media Queries?

  • I am having a philosophical debate with myself over the best place to put media queries within style sheets. I am attempting to structure my CSS modularly (like OOCSS or SMACSS, etc). Given that context, I see two choices:

    1. Put all media queries together in a separate stylesheet or section of the main stylesheet.
    2. Put media queries next to their base counterparts. For example, if I have a module called "news-item", I could put any necessary media query styles right below the definition of that module.

    I am leaning towards the latter, but it would mean I'd have many more separate media queries (separate ones for each logical block of CSS requiring a responsive adjustment).

    Any thoughts on this?
  • It's a great question.

    I think I lean towards the former, but I think it might come down to personal preference.
  • I generally try to use a single style sheet, and always have the media queries at the very bottom.
  • I always found them much easier to manage in one stylesheet so I'm with josh on that one - at the bottom in their respective groups.
  • Just to clarify, I meant the latter part of #1, just like the Joshes.
  • Option 2 sounds like a world of pain having to trawl through your stylesheets when you want to add a new media query to suit a different device your client has just decided is essential to support.

    I always put all media queries in a block at the very end so they will override the relevant style further up the sheet.

    Am now using SASS so I put them either all into one partial which called at the bottom of the main file or into separate partials if the complexity warrants it.
  • For development purposes only, I see no problem in having separate stylesheets for different queries if it helps your workflow, but on deployment combining them into one with the size specific query versions at then end.