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 Perfect

Travis Johnson
Travis Johnson
4,990 Points

Drop down menu does not move to menu bar when resizing.

I have noticed that the drop down menu is remaining in the body of the page and not moving up to the menu bar when you resize the window. I've gone back to the previous videos and can't see what I'm doing wrong.

//Problem: It looks gross in smaller browser widths and small devices
//Solution:  TO hide the text links and swap them out with a more appropriate navigation

//Create a select and append to #menu
var $select = $("<select></select>");
$("#menu").append($select);

//Cycle over menu links
$("#menu a").each(function() {
  var $anchor = $(this);
  //Create an option
  var $option = $("<option></option>");

  //Deal with selected options depending on current page
  if($anchor.parent().hasClass("selected")) {
    $option.prop("selected", true);
  }

  //option's value is the href
  $option.val($anchor.attr("href"));
  //option's text is the text of link
  $option.text($anchor.text());
  //append option to select
  $select.append($option);
  });

//Bind change listener to the select 
$select.change(function() {
  //Go to select's location
  window.location = $select.val();
});
* {
    margin: 0;
    padding: 0;
    font-family: sans-serif;
}

body {
    background: #fff;
}

#menu {
    background: #384047;
    height: 60px;
    padding: 0 5px 0;
    text-align: center;
}

ul {
    list-style: none;
}

ul li {
    display: inline-block;
    width: 84px;
    text-align: center;
}

ul li a {
    color: #fff;
    width: 100%;
    line-height: 60px;
    text-decoration: none;
}

ul li.selected {
    background: #fff;
}

ul li.selected a {
    color: #384047;
}

select {
    width: 84%;
    margin: 11px  0 11px 2%;
    float: left;
}

button {
    display: inline-block;
    line-height: 18px;
    padding: 0 5px;
    margin: 11px 2% 11px 0;
    float: right;
    width: 10%;
}
h1 {
    margin: 40px 0 10px;
    text-align: center;
    color: #384047;
}
p {
    text-align: center;
    color: #777;
}
/** Start Coding Here **/

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

1 Answer

I don't know if you've figured this out already, but you need proper spacing.

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

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