CSS Print: Difference between revisions

From creative crowd wiki
Jump to navigation Jump to search
(Created page with " ==@page== <source lang="css"> @page { size: A5 portrait; margin: 10mm; } </source> ==@page:right @page:left== <source lang="css"> @page:right { margin-left: 3cm; →‎inner: margin-right:1cm; →‎outer: @bottom-right { content: "Testing 123!!!"; } @bottom-center { content: "Testing margin notes"; } } </source> ------------- <source lang="css"> @page:left { margin-right: 10mm; →‎inner: margin-left: 15mm; →‎outer: @bottom-left {...")
 
 
(7 intermediate revisions by the same user not shown)
Line 2: Line 2:
==@page==
==@page==


<source lang="css">
<syntaxhighlight lang="css">
@page {
@page {
   size: A5 portrait;
   size: A5 portrait;
   margin: 10mm;
   margin: 10mm;
}
}
</source>
</syntaxhighlight>


==@page:right @page:left==
==@page:right @page:left==


<source lang="css">
<syntaxhighlight lang="css">
@page:right {
@page:right {
   margin-left: 3cm; /*inner*/
   margin-left: 3cm; /*inner*/
   margin-right:1cm; /*outer*/  
   margin-right: 1cm; /*outer*/  
    
    
   @bottom-right {
   @bottom-right {
Line 24: Line 24:
   }
   }
}
}
</source>
</syntaxhighlight>


-------------
-------------


<source lang="css">
<syntaxhighlight lang="css">
@page:left {
@page:left {
   margin-right: 10mm; /*inner*/
   margin-right: 10mm; /*inner*/
Line 41: Line 41:
   }
   }
}
}
</source>
</syntaxhighlight>


==@page custom sections==
==@page custom sections==


<source lang="css">
<syntaxhighlight lang="css">
@page custom{
@page custom{
   background-color: lightyellow;
   background-color: lightyellow;
    
    
   @bottom-center {
   @bottom-center {
     content: "Testing margin notes";
     content: "A custom note in the bottom-center margin :)";
   }
   }
}
}
Line 57: Line 57:
   page: custom;
   page: custom;
}
}
</source>
</syntaxhighlight>


==@page:first==
==@page:first==


<source lang="css">
<syntaxhighlight lang="css">
@page:first {
@page:first {
   @bottom-center {  
   @bottom-center {  
Line 70: Line 70:
   }
   }
}
}
</source>
</syntaxhighlight>
 
==@page:nth()==
 
<syntaxhighlight lang="css">
@page:nth(3) {
  background-color: pink;
}
</syntaxhighlight>


==pagenumbers==
==pagenumbers==


<source lang="css">
<syntaxhighlight lang="css">
@page{
@page{


Line 81: Line 89:
     }
     }
}
}
</source>
</syntaxhighlight>


==pagebreaks==
==pagebreaks==


Force page breaks before each h1
Force page breaks before each h1:


<source lang="css">
<syntaxhighlight lang="css">
h1 {
h1 {
   break-before: always;
   break-before: always;
}
}
</source>
</syntaxhighlight>


Start a section on the right page
Start a section on the right page:


<source lang="css">
<syntaxhighlight lang="css">
section {
section {
   break-before: right;
   break-before: right;
}
}
</source>
</syntaxhighlight>


==hyphens==
==hyphens==


<source lang="css">
<syntaxhighlight lang="css">
html{
html{
     hyphens: auto;
     hyphens: auto;
     hyphenate-limit-chars: 8;
     hyphenate-limit-chars: 8;
}
}
</source>
</syntaxhighlight>


==display links in print==
==display links in print==
<source lang="css">
<syntaxhighlight lang="css">
a[href]:after {
a[href]:after {
content: ' (' attr(href) ')';
content: ' (' attr(href) ')';
}
}
</source>
</syntaxhighlight>
 
==generated pagenumbers in a table of contents==
 
See: https://pagedjs.org/documentation/-cross-references/#target-counter()
 
<syntaxhighlight lang="css">
#toc a::after {
  content: "page: " target-counter(attr(href url), page);
}
</syntaxhighlight>


= Links =
= Links =


==Paged Media CSS references==
Paged Media CSS references:


* https://developer.mozilla.org/en-US/docs/Web/CSS/Paged_Media
* https://developer.mozilla.org/en-US/docs/Web/CSS/Paged_Media


==Using media queries: @media print, @media screen==
Using media queries: @media print, @media screen


* https://developer.mozilla.org/en-US/docs/Web/CSS/@media
* https://developer.mozilla.org/en-US/docs/Web/CSS/@media
* https://developer.mozilla.org/en-US/docs/Web/Guide/Printing
* https://developer.mozilla.org/en-US/docs/Web/Guide/Printing
Paged.js documentation:
* https://pagedjs.org/documentation/

Latest revision as of 13:05, 5 July 2023

@page

@page {
  size: A5 portrait;
  margin: 10mm;
}

@page:right @page:left

@page:right {
  margin-left: 3cm; /*inner*/
  margin-right: 1cm; /*outer*/ 
  
  @bottom-right {
    content: "Testing 123!!!";
  }
  
  @bottom-center {
    content: "Testing margin notes";
  }
}

@page:left {
  margin-right: 10mm; /*inner*/
  margin-left: 15mm; /*outer*/

  @bottom-left {
    content: "Testing margin notes";
  }

  @bottom-center {
    content: "More margin notes";
  }
}

@page custom sections

@page custom{
  background-color: lightyellow;
  
  @bottom-center {
    content: "A custom note in the bottom-center margin :)";
  }
}

section#custom{
  page: custom;
}

@page:first

@page:first {
  @bottom-center { 
    content: ""; 
  }
  @bottom-right { 
    content: ""; 
  }
}

@page:nth()

@page:nth(3) {
  background-color: pink;
}

pagenumbers

@page{

    @bottom-left{
        content: counter(page);
    }
}

pagebreaks

Force page breaks before each h1:

h1 {
  break-before: always;
}

Start a section on the right page:

section {
  break-before: right;
}

hyphens

html{
    hyphens: auto;
    hyphenate-limit-chars: 8;
}

display links in print

a[href]:after {
	content: ' (' attr(href) ')';
}

generated pagenumbers in a table of contents

See: https://pagedjs.org/documentation/-cross-references/#target-counter()

#toc a::after {
  content: "page: " target-counter(attr(href url), page);
}

Links

Paged Media CSS references:

Using media queries: @media print, @media screen

Paged.js documentation: