Why does a block element take the full width of its parent?
Quick answer
In normal flow, a block with width: auto generally expands across the available inline space in its containing block. That is the default, not necessarily a bug. Set a width such as 50% to make it narrower, or use max-width to limit it. Remember that padding, borders, box-sizing, and minimum or maximum width rules can affect the rendered size.
The question, the details, the next step.
A practical checklist
Identify the element’s containing block and the inline space available inside it.
Check whether the element has an explicit
widthor is usingwidth: auto.Inspect
min-widthandmax-widthfor constraints that may affect the result.Compare content width with padding and borders; check the
box-sizingvalue.Test a small example with a known parent width before adjusting the full layout.
A few more useful answers
Does a full-width block mean its content fills the whole box?
No. The block’s box can span the available width while its text or other content occupies only part of it.
What does `width: 50%` use as its reference?
It is calculated relative to the containing block’s width. [S2]
Why can a maximum width fail to match the size I expect?
A maximum width is a constraint, not a promise of one exact rendered size. Available space, the specified width, and other sizing rules can affect the result. [S2]
Sources
References used for this guide.
- [S1] The CSS box model: Available space for block boxes developer.mozilla.org · Checked
- [S2] The CSS width property developer.mozilla.org · Checked
