G
28

Why does nobody talk about how confusing CSS floats are for beginners

I spent 2 hours trying to get a simple three-column layout to work using floats in my project... turned out I just needed to clear the parent div. Learned that a YouTube video from 2012 finally explained it to me. Has anyone else hit a wall with something that seems simple on paper but just won't cooperate?
2 comments

Log in to join the discussion

Log In
2 Comments
veraw47
veraw471mo ago
Floats drove me up the wall too til I learned that overflow trick the hard way.
8
troy_adams
troy_adams1mo ago
Man I feel your pain... floats are like a rite of passage nobody warns you about. What finally clicked for me was treating every floated element like it needed a clearfix applied to its container. I started putting a class on all my parent divs that had floated children and it saved me so many headaches. Also using overflow: hidden on the parent worked in a pinch but it wasn't always the best fix for me. Once you get the hang of it though it's one of those things you just never forget.
4