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!
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

Alejandro Ochoa
Courses Plus Student 10,671 Pointshelp with nav bar!
I am trying to create a nav bar where my logo is in the middle and there are nav buttons on both sides, however, I seriously have no clue as how to accomplish this.
1 Answer

Cosmin Cioaclă
21,339 Points<style>
.navigation-left,
.navigation-logo,
.navigation-right {
float: left;
width: 33.33%;
}
.logo {
margin: 0 auto;
}
</style>
<nav>
<div class="navigation-left">
<ul>
<li><a href="#"></a></li>
<li><a href="#"></a></li>
<li><a href="#"></a></li>
</ul>
</div>
<div class="navigation-logo">
<div class="logo">
<a href="/"><img src="logoimage.jpg" alt="logoimage"></a>
</div>
</div>
<div class="navigation-right">
<ul>
<li><a href="#"></a></li>
<li><a href="#"></a></li>
</ul>
</div>
</nav>
Try this out.
Lucas Krause
19,924 PointsLucas Krause
19,924 PointsTo make
margin:0 auto;
working you have to specify a width for.logo
, or am I wrong?But since
<img>
is an inline element you can simply leave off the.logo
<div>
and add the following CSS:Cosmin Cioaclă
21,339 PointsCosmin Cioaclă
21,339 PointsYou are right. The width needs to be specified.
text-align: center should work too.