11

I've got some styles specifically for print, which are being applied correctly with a print media query. The thing is, my layout breaks a bit if you switch to landscape printing, and I'd like to tweak some things for it. Is there any way to define styles for landscape printing?

Zachary Nicoll
  • 339
  • 1
  • 4
  • 14

2 Answers2

31

Media Queries offer matching against the device's orientation:

@media print and (orientation: landscape) {
    /* landscape styles */
}

@media print and (orientation: portrait) {
    /* portrait styles */
}
cimmanon
  • 67,211
  • 17
  • 165
  • 171
2
<style>
    @media print {
        @page {
            size: landscape; /*automatically set to Landscape only*/
        }
    }
</style>

If you want letting the user to choose between the two ways : portrait/Landscape, do :

 <style type="text/css" media="print">
        @page {
            /* portrait/Landscape */
            size: auto;
           /*adding some margins to let the title and the date to be displayed*/
            margin: 40px 10px 35px; 
        }
  </style>
Hicham O-Sfh
  • 731
  • 10
  • 12