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 CSS Layout Techniques Float Layout Mobile First Layout

Lidija Novakovic
Lidija Novakovic
6,634 Points

Why use float:right on last element?

Can someone please explain whats the reason for using float: right on the last child , instead of just float it left as the others? Dont get it =)

1 Answer

Dane Parchment
MOD
Dane Parchment
Treehouse Moderator 11,077 Points

It will be kinda hard to explain so bear with me: Basically this is done to prevent rounding errors that can occur if you do not float the last item to the right. Basically when you float everything to the left using percentage values everything won't exactly add up to 100% do to pixel rounding errors. By floating the last element to the right you will prevent that rounding error from occuring and keep a 100% added value float.

If you need more info let me know!

Lidija Novakovic
Lidija Novakovic
6,634 Points

Thanks for your reply and I think I got it but I thought by calculating margins and paddings correctly then it will be no problem floating all elements to the left?!

Can you give me an example when to use float: right?

Maybe its a stupid question but I want to know reasons for doing.