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

Michael Williamson
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Michael Williamson
Front End Web Development Techdegree Graduate 23,903 Points

creating a drop down menu jquery

drop down menu overlaps the div below, trying to get a drop down menu to push down div the same length as the drop down menu.

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1">
    <title>Practice</title>
    <link rel="stylesheet" href="css/main.css">
  </head>
  <body>
    <header class="main-header">
      <div class="logo">
      <h1>Header 1</h1>
        </div>
<!--
      <div class="menu-bar">Menu<button class="ui-btn ui-shadow ui-corner-all ui-btn-icon-left ui-icon-bars"></button>
      </div>
-->
      <nav id="main-nav">
        <span class="toggle">Menu
        </span>
        <a href="#" class="ui-btn ui-corner-all ui-icon-bars ui-btn-icon-left"></a>
          <ul id="nav">
            <li><a href="">exp</a></li>
            <li><a href="">exp</a></li>
            <li><a href="">exp</a></li>
            <li><a href="">exp</a></li>
            <li><a href="">exp</a></li>
            <li><a href="">exp</a></li>
            <li><a href="">exp</a></li>
            <li><a href="">exp</a></li>
            <li><a href="">exp</a></li>
            <li><a href="">exp</a></li>
            <li><a href="">exp</a></li>
          </ul>
      </nav>
<!--
      <ul>
        <li>SOCIAL</li>
      </ul>
-->
    </header>
    <div class="wrapper">
      <section> 
        <p class="center">
          <span>
            Example Text  <br>
            Example Text!

          </span>
         </p>
        <div class="image">
        </div>
      </section>

    </div>
    <footer class="footer">
      </footer>
    <script src="//code.jquery.com/jquery-1.12.0.min.js"></script>
  <script src="main.js"></script>

  </body>
</html>
* {
  border: 1px solid red; 
}

/*   Header Styling  */ 


.main-header {
  color: white;
  background-color: black;
  padding: 20px 30px 30px 30px; 
  height: 100px;
  font-family: sans-serif;


/*  z-index: 100;*/


}

body {
  margin: 0; 
  background-image: url("../sannyfran.jpg");
  height: 700px; 
  background-repeat: no-repeat; 
  background-size: cover;
  background-position: center; 
  background-attachment: fixed;
}

.main-header h1 {
  font-weight: normal; 

  letter-spacing: .2em; 
  font-size: 1.1em; 
  text-transform: uppercase; 

  text-align: center; 
}

#main-nav {
  margin: 20px 0 0 ; 
  border-top: 1px solid grey;
  border-bottom: 1px solid grey; 
   width: 100%; 
  background-color: black; 

}

#nav.js {
  display: none; 
}


.center {
  color: white; 
  text-align: center; 
  margin: 50px 0 0; 
}

.image {
  height: 250px; 
  width: 250px;
  background-color: lightgrey; 
  margin: 0 auto; 
  top: 50px; 
}
/*
.logo {
  margin: 0 10px; 
  left: 0;
}
*/



ul {
  list-style: none;   
  padding-left: 0px; 
  font-size: 19.2px; 
  display: block; 

}

li {
  padding: 20px 30px 30px 30px; 


}

.nav-ul a {
  text-decoration: none; 
  color: white;
  background-color:  black; 
  width: 100%; 
}


/***********************
 body styling
***********************/

.wrapper {
/*  height: 100%; */

}

/***********************
footer styling
***********************/

.footer {
/*  height: 100%; */
  width: 100%; 
  background-color: black; 
}
$("#nav").addClass("js");

$("#nav").addClass("js").before('<div id="menu">ā˜°</div>');

$("#menu").click(function(){
    $("#nav").toggle();
});

1 Answer

Hi Michael.

Everything is correct with the exception that you are giving your nav a specific height. Changing height to auto will fix your problem. jsFiddle Demo

I hope this helps.