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 trialSamanthi Sembakuttige
1,430 Points@media
@media (max-width: 768px){ body{background-color:green;} }
This is what I've done to make sure @media query is working on my website before set up any more properties and values.
But the color does not change when I adjust the screen size.
Please explain the reason and is this wrong?
7 Answers
Yaroslav Kleshchev
8,744 PointsYou are missing the media type. @media screen and (max-width: 768px){ body{background-color:green;} }
Samanthi Sembakuttige
1,430 PointsThanks anyway Mark.
Mitchell Springer
2,576 PointsCan you possibly copy and paste your html and css documents so we have a better idea of what you have written.
Mark Singleton
5,182 PointsChrome doesn't seem to display the different media rules when I use '@media all' like Guil says earlier in the video. If i leave it at just '@media' it works. Weird.
Matteo Simeone
13,587 PointsHi Mark, maybe you've forgotten to write the "and" keyword between the two "all" and "(max-width: 768px)" arguments.
Hope this helps,
Carlton Whittaker
1,995 PointsI had the same issue as Mark, I removed (all) and it works. I then added the (all) back to my @media query and it now works fine too.
Mark Singleton
5,182 PointsI think it's an issue with Workspaces. I've started downloading the project files and working on them in Notepad++ because it gives better, more consistent results. Workspaces is very quirky and buggy.
Carlton Whittaker
1,995 PointsThanks for the info. I would also recommend http://www.sublimetext.com/ as an alternative to notepad++ and http://codepen.io/ is very useful for viewing your code in real-time.
Mark Singleton
5,182 PointsThanks Carlton, I hadn't heard of Sublime Text before.
Mark Buckingham
5,574 PointsHi,
when you use the @media rule you need to specify the media type/device. If you are querying the screen you would need:
@media screen and (max-width: 768px){ body{background-color:green;} }
Samanthi Sembakuttige
1,430 PointsHi, Thanks, but the vedios I watched did not teach me to specify the media type. Let's say I want it for the purpose of screen and print. However I just tried using screen, but it still does not work. what am I doing wrong?
Mark Buckingham
5,574 PointsSamanthi, you are correct @media by itself should be sufficient for what you want.
In that case I am not sure why yours is not working.
Samanthi Sembakuttige
1,430 PointsSamanthi Sembakuttige
1,430 PointsHi, Is it not working because I write the media queries on the css document? What's the syntax to add external media query to the HTML page?