Forum How do I...?

How do I override @page :left @page :right for certain pages

conner_bw
Hi,

I want a generic rule for left and right pages, example:

@page :left {

  @top-left {
    content: string(title);
    vertical-align: left;
    font-size: 9pt;
  }
}

@page :right {

  @top-right {
    content: string(section-title, last);
    vertical-align: right;
    margin: 0.8em 0;
    font-size: 9pt;
  }
}


This works fine. Titles appear as desired.

Now I need to exclude the the title on any page that matches the following selection criteria:

@page exception {

  @top-left {
	content: none;
  }

  @top-right {
	content: none;
  }
}

div.front-matter > h2:first-child, div.part > h1:first-child, div.chapter > h2:first-child, div.back-matter > h2:first-child {
	page: exception;
}


With the above snippet "title" and "section-title" correcty get removed from the selected pages.

But, the first <p> directly after <h2> (or <h1>) gets pushed to the next page; this is undesired.

Any ideas?
mikeday
Right, content on named pages will be preceded and followed by a page break. If the page you want to override is always the first page, then you could use the :first page selector instead (or the :nth() selector to match a specific page). Currently there is no way to match the particular page on which an element first appears.
conner_bw
mikeday wrote:
Right, content on named pages will be preceded and followed by a page break. If the page you want to override is always the first page, then you could use the :first page selector instead (or the :nth() selector to match a specific page). Currently there is no way to match the particular page on which an element first appears.


Thanks for the reply.

I'm not sure I can use :first? I was under the impression that was the first page of the "book" and no other page.

Also not sure I can use :nth, I have no way of knowing what page a chapter will appear on ahead of time. Maybe JavaScript on the fly? If so, I will need some sort of example.

Basically I'm looking to style the first page of a chapter differently than the rest of the pages. There can be many chapters. Currently looks like:

<div class="chapter" id="some_id"><h2>Title of chapter</h2><p>Foo</p><!-- [...]</div>


Rinse and repeat.

I have control over the XHTML so I'm open to changing it.

Thanks for your time.
mikeday
You can use a named page for chapter and tell Prince that this starts a new named page group, like this:
@page chapter:first {
    ...
}

.chapter {
    page: chapter;
    prince-page-group: start
}
conner_bw
mikeday wrote:
You can use a named page for chapter and tell Prince that this starts a new named page group, like this:
@page chapter:first {
    ...
}

.chapter {
    page: chapter;
    prince-page-group: start
}


Amazing, thanks.