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 trialDarren Hill
929 PointsMaking a div disappear when a 480 max px is reached using media query
A bit lost with this one...thought the right commands were display: none; but not having any luck!
5 Answers
Larry Goodhue
4,246 PointsI believed it was display: none; too. I'll have to look that up and get back to you when I find the problem.
Darren Hill
929 PointsThanks Larry
Larry Goodhue
4,246 PointsI think I may have found something. http://stackoverflow.com/questions/11796297/div-show-hide-media-query
Larry Goodhue
4,246 PointsOf course, you'd need to change the max-width in the first media query to 480px.
Darren Hill
929 PointsYeah I've done that but no luckβ¦ This is how my code looks: @media screen and (max-width : 480px) { .cupcake { display: none; } } might be a glitch in the system..or meβ¦lol
Thanks for your help Larry!
Larry Goodhue
4,246 PointsHm. Well, sorry that that didn't help.
I'll try setting up something similar and see what results I get.
Larry Goodhue
4,246 PointsSo, I set up a test website and wrote out all of the media queries that would cause a paragraph to become hidden in the smaller device viewport range, and it seemed to work fine. I minimized my browser to 480px and the text was gone until I resized the page.
One thing I caught in your code was that there isn't a (min-width) in there. Maybe try this:
@media screen and (min-width: 401px) and (max-width: 480px) { .cupcake { display: none; } }
Also, instead of using .cupcake as a class, try using it as a <div id="cupcake">, and then replace the .cupcake in your media query with #cupcake.
Darren Hill
929 PointsOh great, thanks I'll try that.
Larry Goodhue
4,246 PointsYou're welcome! If it doesn't work even then, you could try emailing someone from Treehouse about the issue; or you could just look it up on Google and see what you get.
Darren Hill
929 PointsThanks guys, have got it sorted. Missed the existing class, and was trying to create a new one...all good!
James Barnett
39,199 PointsJames Barnett
39,199 PointsShow us all of your code, it's possible the issue you can is in the media query itself.