Force landscape orientation in CSS

|▌冷眼眸甩不掉的悲伤 提交于 2021-01-27 04:13:29

问题


I do set to landscape the size property of a CSS file to print pages in landscape

@page {
          margin: 0.1cm;
          size: landscape;
          orientation: landscape;
          size: A4;

Some pages are printed into portrait orientation, some in landscape orientation.

How can i detect and force the pages to be printed in landscape using CSS ?


回答1:


The CSS you provided has problems:

  1. The bracket does not close (missing }),
  2. You overwrite size with A4
  3. orientation seems to exist for media queries, but not as an attribute (source). Hence you can check the orientation, but not set it.

I tried

@page {
    size: A4 landscape;
}

in Chrome 60 on Linux and it worked. Seems not to work in Firefox, though.

You could set the width and height of the <body> to whatever you need (only for printing by using the media query) just like paper.css does.

Alternative

You could add

body {
    transform: rotate(-90deg);
}

Seems to be safe to use.



来源:https://stackoverflow.com/questions/39356258/force-landscape-orientation-in-css

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!