Repository navigation
Draw a position: fixed block on every page, and stack positioned blocks by z-index #601
Copy link
Copy link
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Part of #552 (step 28, missing support, medium priority).
Two faults with positioned blocks:
- A
position: fixedblock is drawn on the page where it appears in the source only. CSS 2.1 §9.3.1 says that in paged media a fixed box "is rendered on every page". That makesposition: fixedthe portable way to put a letterhead, a watermark or a running footer on every page. z-indexdoes not decide which positioned block is on top. Only the text is reordered; the backgrounds stay in document order.
Nested positioning is #599.
Measured on gravitypdf at 60b82630, PHP 8.5.4.
| Document | Browser (print) | mPDF |
|---|---|---|
<div style="position:fixed;top:5mm;left:5mm">FIXEDX</div> followed by six pages of text |
FIXEDX on every page |
on page 1 only |
.a { position:absolute; top:50mm; left:50mm; width:40mm; height:40mm; background:#0f0; z-index:5 }, then .b at (60, 60) mm, the same size, red, with no z-index |
the overlap is green, and x and y both show |
the overlap is red. x is drawn on top of the red |
Cause.
- Fixed. A positioned block's HTML is saved with the page it appeared on (
src/Mpdf.php:14883). It is drawn once, on that page, whenWriteHTML()finishes (:15139-15146). z-index. It becomes an optional-content layer around the block's content (src/Tag/BlockTag.php:506,BeginLayer()atsrc/Mpdf.php:3389)._enddoc()moves each layer to the end of its page, ordered byz-index(src/Mpdf.php:11102-11130). A block's background is not written inside its layer:PaintDivBB()writes it at the page's background marker, so only the text moves up. In the probe, the page stream is the green fill, the red fill,y, then/OC /ZI5 BDCwithxalone.
Fix.
- Fixed. Keep fixed blocks apart from absolute ones, and draw each one on every page from the page it first appears on, as a header is. A document that uses a top-level fixed block to mean "here, on this page" today changes output. Say so in the PR. Decide whether a configuration option keeps today's behaviour, or whether
position: absoluteis the answer for that case. z-index.- Paint each positioned block's background, borders and shadow inside its own layer, with its content.
- Order positioned blocks by
z-index, then by document order, withautoand 0 together. - Negative values go below the in-flow content, which needs a layer below it.
_enddoc()already sorts the layers. What is missing is putting everything a positioned block draws inside its own layer.- In-flow blocks with
z-indexare reordered today, which CSS does not do for boxes that are not positioned. Decide whether to keep that. Existing documents may rely on it.
Tests. A fixed block on a one-page and a six-page document, a fixed block after a forced page break, a fixed block with % offsets on pages of different sizes, and z-index of 5, 0, auto and −1 between two overlapping positioned blocks. Read the order of the fills from the page stream.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request
Activity