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

JavaScript jQuery Basics (2014) Creating a Mobile Drop Down Menu Perform: Part 3

jerred poitra
jerred poitra
7,241 Points

No matter which browser I use, the original menu won't disappear when I shrink the window.

I think my code is identical to chalkley's

@media (min-width: 320px) and (max-width: 568px) { #menu ul { display: none; } }

@media (min-width: 568px) { #menu select, #menu button { display: none; } }

I've tried in chrome, safari, firefox, even IE. Help! I've already tried splitting #menu select and #menu button into two separate pieces

5 Answers

Jeff Wilton
Jeff Wilton
16,646 Points

Your css code looks good to me. I have a couple of things to investigate.

  1. check your browser's console and see if there are any errors which could be breaking the rest of your rendered code.
  2. check that you are using the media="screen" attribute in your index.html file when creating the css link:
<link rel="stylesheet" href="css/style.css" type="text/css" media="screen" title="no title" charset="utf-8">
Erik Nuber
Erik Nuber
20,629 Points

I've been looking for a solution to this as well. It appears the best answer I've found is you have to add screen into the media query

@media screen and (min-width: 320px) and (max-width: 568px) {
  #menu ul {
  display: none;
}
}


@media screen and (min-width: 568px) {
  #menu select 
   {
  display: none;
}
}

I've already checked all the html files and they have the link that is provided in most answers regarding css and having media be equal to screen. However, for some reason, that just doesn't do it even though that is supposed to be enough.

I think I figured out the answer. The code works as it is, but when you check the behavior you reduce the size of the window smaller than 320px. If you carefully reduce the size gradually, you will find the sweep spot where <ul> element disappears. The problem with this media query is that the the range of sweet spot between 320px and 568px is actually very narrow with a very high-resolution display like 4k display as I use.

Marco Kühbauch
Marco Kühbauch
10,099 Points

Hey I got the same issues and I tried another solution. Somehow the second condition with the and operator in the first media query seems to be the problem so I deleted that.

So my logic now is: hide the menu until reaching 320px than hide the select menu and the button AND now show the original menu. This worked better for me.

@media (min-width: 320px) {
  #menu ul {
    display: none;
  }
}

@media (min-width: 568px) {
  #menu select,
  #menu button {
    display: none;
  }
  #menu ul {
    display: block;
  }
}
Glen Bayless
Glen Bayless
1,507 Points

I banged on my keyboard a couple of times then eventually realized in my css I still had //Comments...etc..

Once I commented them properly with /** and **/ the issue went away.