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

HTML Build a Responsive Website Adaptive Design Implementing Media Queries

Making 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!

James Barnett
James Barnett
39,199 Points

Show us all of your code, it's possible the issue you can is in the media query itself.

5 Answers

Larry Goodhue
Larry Goodhue
4,246 Points

I believed it was display: none; too. I'll have to look that up and get back to you when I find the problem.

Thanks Larry

Larry Goodhue
Larry Goodhue
4,246 Points

Of course, you'd need to change the max-width in the first media query to 480px.

Yeah 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
Larry Goodhue
4,246 Points

Hm. Well, sorry that that didn't help.

I'll try setting up something similar and see what results I get.

Larry Goodhue
Larry Goodhue
4,246 Points

So, 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.

Oh great, thanks I'll try that.

Larry Goodhue
Larry Goodhue
4,246 Points

You'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.

Thanks guys, have got it sorted. Missed the existing class, and was trying to create a new one...all good!