【问题标题】:Media Print landscape not working - html css媒体打印景观不起作用 - html css
【发布时间】:2023-02-01 00:58:38
【问题描述】:

我在我的角度 html 页面中使用以下媒体打印类:

@media print {
  @page {
    size: landscape !important;
    orientation: landscape !important;
    max-height: 100%;
    max-width: 100%;
  }
  .no-print,
  .no-print * {
    display: none !important;
  }
  body {
    -webkit-print-color-adjust: exact;
  }
  canvas {
    height: auto;
    width: auto;
  }
  .printClass {
    display: inline-block;
  }
}

但是,它总是尝试打印肖像。有谁知道我做错了什么?

【问题讨论】:

    标签: javascript html css angular printing


    【解决方案1】:

    您可能想要删除大小和方向属性中的 !important 指令,并确保将媒体打印类应用于您想要影响的元素。此外,检查是否有任何其他样式或媒体查询与此媒体打印类冲突,并删除或修改它们。

    这是更正后的媒体打印类,它应该确保页面以横向打印:

    @media print {
      @page {
        size: landscape;
        orientation: landscape;
        margin: 0;
      }
      body {
        -webkit-print-color-adjust: exact;
      }
      .no-print,
      .no-print * {
        display: none;
      }
      .printClass {
        display: block;
      }
    }
    

    此媒体查询将 @page 规则的大小和方向属性设置为横向,删除边距,并将正文的 -webkit-print-color-adjust 属性设置为精确。打印页面时隐藏 .no-print 类及其后代,并且 .printClass 类设置为阻塞。

    【讨论】:

    • 谢谢,但它似乎仍在横向打印。另外,我必须有 printClass 内联块,因为我使用的是画布元素,并且出于某种原因,如果我使用任何其他类型的显示,它会在打印中添加 400 个空白页
    猜你喜欢
    • 2013-06-11
    • 2015-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-04
    • 2013-05-30
    • 2014-01-13
    • 1970-01-01
    相关资源
    最近更新 更多