T
16

The day I realized I was nesting CSS Grid containers wrong for months

I kept getting these weird gaps in my layout and couldn't figure out why until a coworker glanced at my code and pointed out I was using margin instead of gap on the child elements. Has anyone else accidentally mixed up grid gap with margin and spent hours debugging?
2 comments

Log in to join the discussion

Log In
2 Comments
kellymurphy
Yeah that exact thing bit me too. Just remember grid gap controls space between items while margin adds space around them, so using margin can double up and create those weird extra gaps.
5
taylor_moore
oh man, tell me about it. i learned that one the hard way too, spent like an hour trying to figure out why my grid looked all wonky and spread out. it's one of those things that makes total sense once you see it but feels like a trap the first time. definitely sticking to grid gap for spacing between items from now on and just using margin for like, the edge of the container or something specific.
4