Open dholbert opened 3 years ago
This isn't to say that the spec is necessarily wrong, but I want to double-check that the requirements in this area are actually intentional & that it represents what browsers should in fact be doing. (And if not, this section should be updated/broadened to reflect the actual requirements or best-practices here.)
We use PrinceXML for book typesetting, and always override the vertical-align: middle
for page margin boxes. Our goal is a consistent distance between the header/footer and the page area, so we set text-align: bottom
on the top- boxes and text-align: top
on the bottom- boxes.
It would be good to know what the various CSS-to-PDF implementations do. I imagine they care the most about what happens here. CC @faceless2
I'm also thinking, the preferred alignment of headers/footers added by web browsers might be different from what defaults make sense for ones defined by the page: browser-added headers and footers are not really designed as part of the document, so that's probably why historically they've been pushed as far away from the content as possible.
I've always thought that the spec is oblivious of browser-default margins, and that the default UA stylesheet for margin box alignment (https://drafts.csswg.org/css-page/#margin-text-alignment) only has an effect if the content
property in a margin context is not none
. The spec also goes "As with the :before and :after pseudo-elements, a specified content: normal on a page-margin box computes to none." (https://drafts.csswg.org/css-page/#margin-text-alignment).
FYI: I just filed issue #10421 regarding how the default placement (text-align and vertical-align) isn't very useful for vertical writing modes.
The css-page-3 spec aims to specify how headers/footers are aligned on a printed page, but its requirements don't actually match what browsers currently do.
There's some spec text about print header/footer placement here: (a) https://drafts.csswg.org/css-page/#margin-boxes (b) https://drafts.csswg.org/css-page/#margin-text-alignment (c) https://drafts.csswg.org/css-page/#page-properties
This text effectively says that headers/footers should be vertically centered in the margin area. In particular:
text-align
andvertical-align
values that the UA should use for each of the margin-boxes. Nearly all of them havevertical-align:middle
(except for some boxes on the left and right edges of the page, which aren't relevant here).vertical-align
property behaves as specified for table cells." (So the aforementioned defaultvertical-align:middle
is expected to actually get us vertical centering for header/footer text, as shown in the mockups in the spec like https://drafts.csswg.org/css-page/images/header-ex-4.png)However: as far as I can tell, no browser actually does this vertical centering for their default page headers/footers. I tested Chrome, Edge (Chromium-based), Safari, and Firefox, and they all seem to use some sort of fixed offset from the edge of the page or the printable area. The headers/footers don't move if I adjust my page margins (in the print dialog) -- the page content respects the margins that I choose, but the headers/footers stay put.
Here's the testcase that I've been using for this, FWIW (to easily visualize the content area in a printed page):