20
Overheard two devs arguing about margin vs padding at a coffee shop
Was grabbing a latte and these two guys next to me were going back and forth for like 10 minutes over whether margin or padding was harder to debug. One guy said 'margin collapse is the reason I almost quit web design.' That stuck with me. Anyone else have a CSS thing that just drives you up a wall?
2 comments
Log in to join the discussion
Log In2 Comments
reeseanderson6d ago
Margin collapse is literally one of the best things about CSS though... people just don't take the time to understand how it works. I've been doing frontend for years and honestly padding drives me way crazier because you gotta deal with box-sizing and borders shifting everything around. At least margin collapse follows clear rules once you learn the spec, padding just sits there taking up space making your layout calculations annoying.
6
blair_dixon5d ago
Literally one of the best things about CSS" - come on man, margin collapse is the worst. It breaks all common sense about how spacing should work. If I put a 20px margin on a box, I expect 20px of space around it, not for it to randomly vanish because the neighbor has a bigger margin. Padding might be annoying with box-sizing, but at least it stays where I put it. Nothing drives me crazier than stacking elements and watching margins disappear like magic, then having to add a tiny border or overflow hack just to make them behave. You can't even rely on it in flexbox or grid, so why defend it in flow layout when most of us moved to modern layouts anyway? Wouldn't it be better if CSS just gave us consistent spacing that never collapsed at all?
8