Web Design Box Study

CSS NOTES

Start with three observations

01

Content width and outer width

With content-box, padding and border are added to width: 144 + 2 × 16 + 2 × 2 = 180px. Two cards plus a 16px gap do not fit the 328px inner container.

Check box-sizing before treating width as the outer measurement.

02

The inside of border-box

A border-box width of 144px includes padding and borders. Content width is 144 − 32 − 4 = 108px. Two 144px outer widths and a 16px gap total 304px.

The same width value can produce a different content width and line count.

03

The exact-fit boundary

A 368px container with 16px padding on each side leaves 336px. Two 160px border-box cards plus a 16px gap fit exactly. Increasing the card width moves the next card to a new line.

This example uses flex: 0 0 auto to prevent shrinking. Do not generalize it to every responsive layout.

Standards references

CSS Sizing · box-sizing
CSS Flexbox · line breaking
CSS Box Alignment · gaps