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.

CSS Unused CSS Stages Media Queries Media Features and Media Types

Jason Larkin
Jason Larkin
13,970 Points

Media query not working

@media screen and ( max-width: 768px )  { {background:#FF6347; color:white;}
}

I have been having trouble with this media query. Can someone help? Thank you in advance for any replies.

3 Answers

Paul Johnson
Paul Johnson
18,924 Points

Hi Jason,

You don't have any selectors before the declaration so the browser doesn't know what you are trying to apply the rule to. If you are trying to change the background and color of the body for example it should be

@media screen and (max-width: 768px) {
    body {
       background: #FF6347;
       color: white;
    }
}

Hope this helps.

Jason Larkin
Jason Larkin
13,970 Points

Thank you for the code- it was the solution!

Hey Jason, it looks like you're not assigning the background or colour to anything:

Perhaps you want to try this:

@media screen and ( max-width: 768px ) { .containerClass { background:#FF6347; color:white; } }

You would need to have defined the class name in your HTML code too, or select .body if that's what you're referring to as Paul suggested

Jason Larkin
Jason Larkin
13,970 Points

Thank you Nicholas- that solved it!