Skip to main content

One post tagged with "fit-content"

View All Tags

My Div Says 'Test' But Takes Up the Whole Width? Understanding Block Elements and Content Size

· 10 min read
Mahmut Salman
Software Developer

I added a child div with just "Test" in it. It's centered perfectly, but when I inspect it in DevTools, the content area is HUGE! 🤔 The div stretches across the entire width even though the text is tiny. I get why it happens (block elements take full width), but shouldn't the div just be the size of "Test"? This conversation taught me the fundamental difference between block-level and inline-level elements—and exactly how to fix it.