Forum How do I...?

Fixing the position of margin box elements

jbzech
I'm trying to style the page number and header text differently (ex: italics on header, but roman on page number). As far as I can tell, there is no way to do that if you are working in the same margin box (top-left, top-right, for example).

Typically, my header line looks like this:

content: counter(page) " \A0  \A0  \A0  \A0  \A0 \A0" string(chapter-title);


It looks like the only way to style them differently is to place them in separate margin boxes. I'd prefer not to use the corner boxes, as they hang out over the margin instead of the text. I can move them in with some negative padding/margins, but then their placement will vary depending on the number of digits.

So I'd prefer to use top-left/top-right for the folio and top-center for the header, aligning them appropriately for the left or right pages.

But those three boxes are variable width, and I can't seem to get a fixed width out of them. Is it possible?

This doesn't work, but I'd like it to:

@page :left {
      @top-left {
        content: counter(page);
        text-align: left;
        width: 1cm;
        }
      @top-center {
        content: string(chapter-title);
        text-align: left;
        }
}


This would allow me to place the page number reliably aligned with the text on the left edge (regardless of digits) and reliably control the space between the page number and the header content (again, regardless of content).

Is there another way to accomplish this? (Or is there a way to style things within a "content:" property?)

Edited by jbzech

mikeday
When you start wanting to style text in different ways it becomes easier to use the "flow" property to take an element from the document and move it up to the page margin boxes. This allows arbitrarily styled content to be used in the headers and footers, including even images and tables.
dauwhe
jbzech
Thanks, dauwhe. Your post is incredibly helpful. I talked editorial out of the differing styles for this project, but the issue will come up again I'm sure.

My hesitation lies in adding non-page content to my HTML (even though I know it will be moved out of the flow). So to get the chapter head, for example, I'd need to add an additional bit of text where the head is repeated (such as <p class="chapterHead">Terrific Chapter</p>) and then remove that p tag with the flow property, right?

I'm actually going DocBook to HTML with a little Perl post-processing before the thing goes into Prince. So it shouldn't be difficult to accomplish in XSL or Perl. I'll give it a try.