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?
Asked
Active
Viewed 1.2k times
11
-
1Did you try the `(orientation: landscape)` media query in combination with `print`? – cimmanon May 16 '13 at 20:43
-
Wow, well no, I hadn't tried that for some reason. Works like a charm. Make it an answer and I'll accept it. – Zachary Nicoll May 16 '13 at 20:54
2 Answers
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
-
1
-
1Unfortunatly, This is not working in the current version of Chrome. – Hicham O-Sfh Nov 14 '20 at 15:22
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