Background: I have a PHP script that generates a long HTML/CSS document that gets converted to a PDF with WkHtmlToPdf.
At one point in the document, we enter a dynamic area with a variable number of entries, some of which include large images. I want to redraw a header on every page.
Point of clarification: This is a repeated header in the print view of a section of a webpage, not just a header for the entire page.
How I want to do that is via CSS. For example (pseudocode):
#some_region:pagebreak {
background-color: #fcc;
border-color: #000;
border-style: solid;
border-width: 0 0 1px 0;
content: "Our Header Here";
}
Of course, this fictitious CSS3 selector does not exist!
Are there any clever CSS hacks that can be used to display an element after any page-breaks within a certain container?
To illustrate: https://scott.arciszewski.me/public/23277702.php
page-break-before: auto instead of . page-break-before: always. The "auto" will break the page only if the contents are at the end if the page, this will prevent breaking the page and leaving a lot of blank space. Save this answer.
We can add a page break tag with style "page-break-after: always" at the point where we want to introduce the pagebreak in the html page.
You can use page-break-inside="avoid" on <div> "B". This is probably closer to what you want. If "B" does not fit on the page with "A", "B" will all be moved to the next page.
What about a position: fixed;
header in @media print
?
That would force a header on each printed page.
Something like:
@media screen {
.print-header {
display: none;
}
}
@media print {
.print-header {
position: fixed;
...
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With