diff --git a/Part06_Generated-Content-in-Margin-Boxes.md b/Part06_Generated-Content-in-Margin-Boxes.md new file mode 100644 index 0000000000000000000000000000000000000000..2e05943f460134d1dd10c94a4fce99c9135ad69f --- /dev/null +++ b/Part06_Generated-Content-in-Margin-Boxes.md @@ -0,0 +1,663 @@ +# Generated Content in Margin Boxes + +CSS modules for paged media add the possibility to use the `content` property in special area of the pages: the margin boxes. In addition, combinations of syntaxes and properties create elements needed to design a book: page number and running headers and footers. + + + +## Margin boxes of a page + +A page box consists of two types of area: page area and page margin boxes. + +The **page area** is the content area of a page box. It is the space into which all your HTML content will flow. When this content runs out of room, another page will be automatically created. It's what the chuncker part of paged.js do. + +The margins of a page are divided into sixteen boxes where you can put generated content like page number and running title. These boxes are called **margin boxes**. + +Each have its own margin, border, padding, and content areas. By default, their sizes are determined by the margin of the page box. + + The figure bellow represent the sixteen margin boxes of a page defined by the W3C: + + + + +You can select this margins boxes in the `@page` rules with rules such as `@top-left`, `@bottom-right-corner`, `@left-middle`, etc. You add content in a page-margin box with the `content` property. + +The code below put your title in the `@top-right` margin box of all right pages: + +```CSS +@page:right { + @top-right { + content: "My title"; + } +} +``` + +List of the margin boxes: + +```CSS +@top-left-corner {} +@top-left {} +@top-center {} +@top-right {} +@top-right-corner {} +@left-top {} +@left-middle {} +@left-bottom {} +@right-top {} +@right-middle {} +@right-bottom {} +@bottom-left-corner {} +@bottom-left {} +@bottom-center {} +@bottom-right {} +@bottom-right-corner {} +``` + + + +## Page Counter + +To define page numbers, paged.js uses a CSS counter that gets incremented for each new page. + +To insert a page number on a page or retrieve the total number of pages in a document, the W3C proposes a specific counter named `page`. The counters declaration must be used within a `content` property in the margin-boxes declaration. The following example declares the page number in the bottom-left box: + +```CSS +@page { + @bottom-left { + content: counter(page); + } +} +``` + +You can also add a bit of text before the page number: + +```CSS +@page { + @bottom-left { + content: "page " counter(page); + } +} +``` + +To tally the total number of pages in your document, write this: + +```CSS +@page { + @bottom-left { + content: "Page " counter(page) " of " counter(pages); + } +} +``` + + + +**Reset the page counter** + +Don't work correctly in paged.js for now. [Issue #31](https://gitlab.pagedmedia.org/tools/pagedjs/issues/91) + + + +## Named String: classical running headers/footers + +The fastest way to create running headers/footers is to use what is already in your content. **Named strings** are used to create running headers and footers: they copy text for reuse in margin boxes. + +First, the text content of the selected element is cloned into a named string using `string-set` with a custom identifier (in the code below we call it “title”, but you can name it whatever makes sense as a variable). In the following example, each time a new `