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 Foundations The Box Model Positioning Properties

Antoine Boillot
Antoine Boillot
10,466 Points

CSS : absolute positioning vs float ?

Hi all,

I'm currently going through the CSS foundation path, and I'm not sure to fully understand the difference between absolute positioning and float in CSS.

They are kind of look alike to me.

In what context should I prefer one or the other ?

Thanks

Ryan Smee
Ryan Smee
3,392 Points

Hi,

When I first started using CSS, I read a really simple rule somewhere that helped me to understand when to use a floated div and when to use absolute positioning.

If you want your div to interact and be effected by the other divs on the page, use floats. If you want you div to stay in the same place no matter how the dom changes around it, use absolute positioning.

It's a simple rule and of course there are exceptions, but its a good place to start. Hopefully this helps?

1 Answer

Ryan Smee
Ryan Smee
3,392 Points

Good to here :)