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 Mobile-First CSS Layout Mobile-First CSS Layout Using a Mobile First Approach

Alex Hort-Francis
Alex Hort-Francis
17,074 Points

I wonder why Workspaces is highlighting 'min-width' in red?

This is the same in Guil's Workspace & mine. It applies to the opening curly brace after the media query declaration too.

Any ideas why this is? What is Workspaces trying to tell us by doing this?

1 Answer

I've noticed this numerous times on the Team Treehouse editor.

My initial guess was that it related to the part of the editor that reads text entry and offers syntax highlighting (to offer auto-fill to save typing everything out for example), and that it has an issue recognising/understanding what is meant by media queries. So even though 'min-width' is a standard CSS property, then because it's entered as part of a media query then the editor can't parse correctly what is going on?

However, the actual answer is that the editor is looking for you to explicitly enter a media types for your media queries (given that media queries aren't just used to alter CSS rules on screens, but also for printers and other media).

So the editor wants you to explicitly state that your media query is for the type 'screen'. Once you add in that key word to the selector on the rule, the red highlighting on 'min-width' and the curly braces will disappear, as it then sees the query as 'correct' in terms of it's syntax and not breaking any rules.

From what I've read more generally isn't essential to explicitly state the media type in most contexts in media queries, though someone with more experience may want to comment on that?

Example:

/*No issues with the below media query:*/
@media screen (min-width: 769px) {
    .container {
        width: 70%;
      max-width: 1000px;
        margin: 0 auto;
  }
}

/*Red highlights/original text*/
@media (min-width: 769px) {
    .container {
        width: 70%;
      max-width: 1000px;
        margin: 0 auto;
  }
}