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


Paul Murphy
Paul Murphy
6,162 Points

Aligning nav central in responsive design

Hi Guys,

I have 2 navs one is in the header section another is outside of it. When I resize the browser to a mobile viewport size id like my secondary nav to display centrally without using margin-left property with px unless that is the only way?

I attempted margin: auto; to no success

Hope you can help!

1 Answer

Hi Paul,

It would be useful if you could provide some code.

I think margin: auto should do the trick, you just need to put your second nav in a container like

<div id="nav"> <ul> <li><a href="">home</a></li> <li><a href="">about</a></li> <li><a href="">work</a></li> <li><a href="">contact</a></li> </ul> </div>

and then the css

nav {

width: 100%;
min-height: 100px;


nav ul {

margin: 0 auto;
width: 50%;
border: 1px solid #333;
padding: 0;


nav ul li {

min-width: 24%;
min-height: 30px;
display: inline-block;
background-color: #ccc;


nav ul li a {

width: 100%;
display: block;
text-align: center;
text-decoration: none;
line-height: 35px;


You can adjust the widths and heights to your needs. I am not sure if this is the answer your were looking for, It's just an assumption.

Regards, Tomek

Paul Murphy
Paul Murphy
6,162 Points

You, my good fellow have been a great help! Thanks!!