You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
A block with max-width and margin: auto renders full width, because min-width and max-width are not read on blocks #588
max-width and min-width are never read on a block. The common centred-container pattern, max-width with margin: auto, renders the full width of the page.
Measured on gravitypdf at 60b82630, PHP 8.5.4, from the filled rectangles.
Rule on <div>aa</div>, 180 mm page area
Browser
mPDF
max-width: 100mm; margin: 0 auto
a 100 mm box at x = 55 mm
a 180 mm box at x = 15 mm
width: 150mm; max-width: 100mm
100 mm
150 mm
width: 50mm; min-width: 80mm
80 mm
50 mm
max-width: 50%
90 mm
180 mm
Cause.setCSS() reads WIDTH into blk[…]['css_set_width'] (src/Mpdf.php:19356-19359). Nothing reads MAX-WIDTH or MIN-WIDTH for a block; Img reads them for images only (src/Tag/Img.php:138-141). BlockTag::open() works out auto margins only when css_set_width is set (src/Tag/BlockTag.php:830-875). With no width, the block fills its container, and margin: auto computes to 0.
Fix.
In BlockTag::open(), before the auto margins are worked out, take the width the block would have: css_set_width, or else the container's inner width less margins, borders and padding.
Clamp that width by max-width, then by min-width. Percentages resolve against the container's inner width, as width does.
If the clamped width differs, set css_set_width to it, so the existing auto-margin code centres or aligns the block.
Floats and positioned blocks take the same clamp.
box-sizing: border-box changes what these values measure; that, and min-/max- on tables and cells, is #593. #553 moves centred blocks with a set width on pages of a different width, and this change goes through the same path.
Tests. Each row above, margin-left: auto alone, an rtl block, a float, a positioned block, nested containers, and a block with padding and borders.
Activity
Hold a block's width within its min-width and max-width (#588) (#691)