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

Horizontal nav won't center

I don't know what I'm doing wrong here. Centering the nav won't work for a reason I can't find.

  <header class="siteHeader">
      <div class="wrap">
        <h1 class="siteHeading">WebDev</h1>
        <nav class="siteNav">
          <ul class="linkTo">
            <li><a href="#">AA</a></li>
            <li><a href="#">BB</a></li>
            <li><a href="#">CC</a></li>
            <li><a href="#">DD</a></li>
            <li><a href="#">EE</a></li>
            <li><a href="#">FF</a></li>
            <li><a href="#">GG</a></li>
          </ul>
        </nav>
      </div>
    </header>
* {
  box-sizing: border-box;
}

.wrap {
  width: 70%;
  margin: 0 auto;
}

.linkTo {
  list-style: none;
  padding: 0;
  margin: 0;
}

/**********************
HEADER
***********************/

.siteHeading {
  text-align: center;
}

.siteNav,
.linkTo,
.linkTo li {
  display: inline-block;
}

.siteNav {
  text-align: center;
}

2 Answers

Konrad Pilch
Konrad Pilch
2,435 Points

I think you need to marign 0 this <header class="siteHeader"> and give it a container.

I noticed that if I keep .'siteNav' in the rule where inline-block is applied I need a new rule of

.siteNav {
      width: 100%; 
}

or I can omit '.siteNav' from the rule where the display mode is changed to include only the unordered list and list items.

.linkTo,
.linkTo li {
    display: inline-block;
}
Tim Wall
Tim Wall
9,570 Points

One way you can get your horizontal nav to center is to replace the selected class of .siteHeading with .siteHeader. That way everything inside the header div will inherit the property value {text-align: center;} so long as it is not overridden later.