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 trialDesmond Dallas
6,985 PointsAlign item in nav bar
Hi, I'm trying to float the last item (contact) to the right. Can anyone show me where I'm going wrong please.
<nav> <ul class="container"> <li><a href="#home">Home</a></li> <li><a href="#about">About</a></li> <li><a href="#articles">Articles</a></li> <li style="float: right"><a href="#contact">Contact</a></li> </ul> </nav>
.container { list-style: none; flex-wrap: wrap; display: flex; padding: 10px; background:#3db5da; }
li a {
color: #fff;
padding: 10px;
background: #3db5da;
text-decoration: none;
display: block;
}
1 Answer
Jamie Reardon
Treehouse Project ReviewerIn your code you are using flexbox, it is pointless using a float on the child li when you have a flexbox container as your ul element.
With that being said, you can simply add one property to achieve your goal:
li:last-child {
margin-left: auto; /* Absorbs any extra space inside the flex-container, therefore, pushing any element to its left away. */
}
Floats are outdated and not intended for layout, they are best used for wrapping text around images.
Desmond Dallas
6,985 PointsDesmond Dallas
6,985 PointsGreat Thanks