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
img { display: block; margin: 0 auto } does not centre the image #589
img { display: block; margin: 0 auto } is the usual way to centre an image, and it does nothing. The image stays inline, on the same line as the text around it, and auto margins count as 0.
Measured on gravitypdf at 60b82630, PHP 8.5.4, from the image's cm matrix and the positions text is drawn at.
Img::open() reads DISPLAY only to skip the image for none (src/Tag/Img.php:34-36). The image always becomes an inline object in the text buffer.
margin-left and margin-right go through SizeConverter (src/Tag/Img.php:69-84). It reads auto as a length in an unknown unit, which is 0.
Fix.
For display: block on an img, end the current line before the image and after it, as a block would.
Put the image on a line of its own, and place it by its margins: both auto centre it, and one auto pushes it to the other side. Use the container's inner width, less the image's width, padding and borders.
Leave text-align out of it; it does not apply to a block-level image.
Floats, images in table cells, and images inside <columns> keep their paths.
This can be done on its own in Img and the line-breaking code. It does not need the general display work in #598, though that issue covers display: block on other inline elements.
Tests. Each row above, the image in a table cell, an rtl container, and an image with padding and a border.
Activity
Put an image with display: block on a line of its own, placed by its …
Put an image with display: block on a line of its own, placed by its …
Merge pull request #693 from GravityPDF/fix/589-block-image-auto-margins