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 CSS Basics (2014) Enhancing the Design With CSS Media Query Basics

Jorge Amezcua
Jorge Amezcua
2,425 Points

It dosen't work! I have tried for 1 hour and nothing! Help!

This is my code:

@media (max-width: 960px) { body { background: blue; } p { color: white; } }

@media (max-width: 480px) { body { background: darkred; } }

Am I wrong? or what happen? Thank you!

4 Answers

Jason Jones
Jason Jones
22,155 Points

I had to add the "all and" keywords to get it to work. @media all and (max-width: 960px) ...

Phill Haines
Phill Haines
6,333 Points

Jason,

Thank you so much for the fix!

Christine Hendrickson
seal-mask
.a{fill-rule:evenodd;}techdegree
Christine Hendrickson
Front End Web Development Techdegree Student 5,410 Points

I tried the suggestions above and I still couldn't get this working.

Just in case someone else is struggling with this, I found the solution (for me) in another thread. Change the second entry (for dark red) to something larger than 480 - I tried 600 and this worked perfectly for me. Apparently, my browser would only shrink to a size that was larger than 480 so the change wasn't firing.

Hope this helps! Happy Coding ☺

Julianna Kahn
Julianna Kahn
20,701 Points

Wow, 600px! That did work, thanks.

robiny
robiny
7,334 Points

That worked for me! Thank you! Saved me an hour of breaking my head.

I am having the same trouble, and adding the 'all and' didn't work for me.

Rouillie Wilkerson
Rouillie Wilkerson
10,407 Points

Make sure you're recognizing the body from the header. If you scroll down, then resize, you'll see that the blue and white is being applied when you reach the 960px,mark.