I have a number of pages which I'd like to set up so that printing defaults to A4 landscape in somecases but A3 portrait in others.
Based on the answer in css print styling I have tried to set up the following in a print.less file
@media print{
.print-portrait-a3 {
@page {
size: A3 portrait;
margin: 0.5cm;
}
}
.print-landscape-a4 {
@page {
size: A4 landscape;
margin: 0.5cm;
}
}
.print-portrait-a4 {
@page {
size: A4 portrait;
margin: 0.5cm;
}
}
}
I'm then putting .print-portrait-A3 classes etc at the top of the page sections that I'm printing to try and get them to print to the different page sizes.
However, I can't get this to work - whichever is the last style in my css is the one that gets used by all pages.
I'm only really just beginning with CSS (probably obvious that I don't have much of a clue) so would appreciate some explanation to sort out my misunderstandings.
I'm using jade and bootstrap
You can use CSS to change the appearance of your web page when it's printed on a paper. You can specify one font for the screen version and another for the print version. You have seen @media rule in previous chapters. This rule allows you to specify different style for different media.
The @page CSS at-rule is used to modify some CSS properties when printing a document.
Developer Tools. The DevTools ( F12 or Cmd/Ctrl + Shift + I ) can emulate print styles, although page breaks won't be shown. In Chrome, open the Developer Tools and select More Tools, then Rendering from the three-dot icon menu at the top right. Change the Emulate CSS Media to print at the bottom of that panel.
I don't think you can nest CSS under a div, just under a media query. Here is some untested code adapted from http://www.w3.org/TR/css3-page/#page-size-prop:
/* style sheet for "A4" printing */
@media print and (width: 21cm) and (height: 29.7cm) {
@page .print-landscape-a4 {
margin: 3cm;
size: A4 landscape;
}
}
You might also look at https://stackoverflow.com/a/14621368/1584531
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With