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 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,422 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,702 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,419 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.