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 The Solution

Ermin Mekic
Ermin Mekic
1,063 Points

Center navigation bar inside header

Can somebody explain the following to me, please:

Why does the navigation bar have full width with the following :

nav ul {
  display: inline-block;
}

And why is the navigation bar narrower in the solution:

nav {
  display: inline-block;
}

Thank you!

1 Answer

Thomas Chappel
Thomas Chappel
6,342 Points

In your first snippet of code:

nav ul { display: inline-block; }

you targeted the unordered list inside the nav element. Thus the nav element still retains its default block display and takes the full width of the viewport.

In your second snippet of code: nav { display: inline-block; }

you targeted the nav, assigning display: inline-block. This makes the container behave partly as block level, partly as inline level element. It first narrows to the width and height of its children elements (if it didn't have already its own width and height specified) and itwill stack horizontally as inline elements do. However you can still assign width and height to an inline-block element, as well as padding and margins.

I hope this will help you.

Ermin Mekic
Ermin Mekic
1,063 Points

This helps a lot. Thank you very much!