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

CSS

Dropdown menu with CSS

I am trying to create a dropdown menu for the mobile version of a website. It should show when the person clicks on 'Menu'.

Why the dropdown menu shows on :hover but when I change the css for .dropdown:target > .dropnav it doesn't work ? And why the dropdown menu doesn't seem to take the styles (padding, text-align....) ? I would like it centered on the page.

/* ------Navigation------- */

.main-nav li, .dropnav li {
  text-align: center;
  }

.main-nav a, .dropnav li a {
  padding: 10px 15px;
  text-align: center;
  text-transform: uppercase;
  font-size: .95em;
  display: block;
}

a:hover {
  color: #939393
}

.dropdown {
  position: relative;
}

.dropnav {
  position: absolute;
  display: none;
}

.dropnav li {
  border-bottom: 1px solid rgba(255,255,255,.2)
}

.dropdown:hover > .dropnav {
  display: block;
}
<body>
  <header class="main-header">
    <ul class="main-nav">
      <li class="dropdown">
        <a href="#">Menu</a>
        <ul class="dropnav">
          <li><a href="#">Home</a></li>
          <li><a href="#">Cardapio</a></li>
          <li><a href="#">Contato</a></li>
        </ul>
      </li>  
    </ul>
  </header>

Thank you !