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 trialGabriel Ward
20,222 PointsCentering the main-nav
In the video, Guil floats the main-nav to the right. I'm curious to know what the best way to center the main-nav would be. Is it possible to use float on the main-nav and center it?
2 Answers
Craig Watson
27,930 PointsHi Gabriel,
You can use margin to center an element within its container providing it has width that is not set to auto, and the child width is not set to say 100% filling the parent container.
.my-nav {
margin: 0 auto;
}
As basic as this may seem if the parent element styles were as follows:
.my-nav-container {
width: 100%;
}
No floats needed and no worrying about clearing floats either.
You should be good to go :)
Hope this helps
Craig
Robert Szabo
7,999 PointsHey Gabriel,
I don't think so you need to move anything, since the ul , h1 , div are all block-level elements.
Gabriel Ward
20,222 PointsGabriel Ward
20,222 PointsHi Craig,
Thanks. And in this case here with this project, to display the ul would beneath the h1, ul element would need to be moved into it's own container div separate from the div with the h1 class='name' right?
So we'd change
to something like,