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

brandonlind2
brandonlind2
7,823 Points

I cant seem to be able to center the a the tags in my dropdown menu

Any ideas as to way my a tags arent centering? I'm trying to use text align center but it doesnt seem to be working

<nav>
   <ul>
    <li class="main-nav"><a href="index.html">Home</a></li>
    <li class="main-nav">
     <span>Content 1</span>
     <ul class="dropdown-menu">
      <li><a href="page1.html">page 1</a></li>
      <li><a href="page2.html">page 2</a></li>
      <li><a href="page3.html">page 3</a></li>
     </ul>
    </li>
    <li class="main-nav">
     <span>Content 2</span>
     <ul class="dropdown-menu">
      <li><a href="page4.html">page 4</a></li>
      <li><a href="page5.html">page 5</a></li>
      <li><a href="page6.html">page 6</a></li>
     </ul>
    </li>
   </ul>
  </nav>
html{ 
    width: 940px;
    margin: auto;
    padding: 0; 
    }
body{
    background-color: blue;
    max-width: 100%;
    padding: 0;
    margin: auto;
    }
header{
    max-width: 100%;
    padding:0;
    margin: auto;
    }
nav {
    max-width: 100%;
    padding: 0;
    margin: auto;
    }
nav ul{ 
       max-width: 100%;
       padding:0;
       margin: auto;
       }
nav li { 
   display: inline-block;
   list-style:none;
   max-width: 100%;
   padding: 0;
   margin: auto;
        }
nav a{ 
         text-align: center;
          padding: 0;
      margin: auto;
     }      
.main-nav{
    max-width: 100%;
    padding: 0;
    margin: auto;
    position: relative;
}
.dropdown-menu {
       background-color: white;
        max-width: 100%;
        padding: 0;
        margin: auto;
        display: none;
        position: absolute; 
}
.main-nav:hover .dropdown-menu{
        display: block;
}
.dropdown-menu li {
    text-align: center;
}
section {
    max-width: 100%;
    padding: 0;
    margin: auto;
    }
footer {
    max-width: 100%;
    padding: 0;
    margin: auto;
    }   

2 Answers

<center>

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,252 Points

Try applying it when the list items are on hover. The list items only show up when you're hovering which is triggered by a pseudo class so it won't take effect unless you tell CSS that's what you want to do.

.main-nav:hover .dropdown-menu{
        display: block;
       text-align: center;
}
brandonlind2
brandonlind2
7,823 Points

what if I want the .main-nav to the right or left wouldnt that center the nav also not just just he drop down menu within the nav?