通过 css 控制 window.print 的样式

打印页面隐藏打印按钮

1
2
在 button 按钮加一个 class 样式
class="print-button-container"

  调用 window.print 方法的页面加以下css

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<style scope lang="scss">
@media print {
  .table-print-disable {
    display: none;
  }
  @page {
    /* 纵向打印 */
    size: portrait;
 
    /* 横向打印 */
    //size: landscape;
 
    /* 去掉页眉页脚*/
    margin-top: 0;
    margin-bottom: 0;
  }
  /* 告诉浏览器在渲染它时不要对框进行颜色或样式调整 */
  * {
    -webkit-print-color-adjust: exact !important;
    -moz-print-color-adjust: exact !important;
    -ms-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
 
  /*打印不显示打印按钮*/
  .print-button-container {
    display: none !important;
  }
 
  /* 伪类 :first 用于匹配到文档的第一页, 首页上页边距设置为 10cm */
  @page :first {
    margin-top: 10cm;
  }
 
  /* 通过分别设置左页和右页不同的左右页面距,为装订边留出更多的空间 */
  /**/
  @page :left {
    margin-left: 2.5cm;
    margin-right: 2.7cm;
  }
  @page :right {
    margin-left: 2.7cm;
    margin-right: 2.5cm;
  }
}
</style>

  

posted @   柠檬-不加糖  阅读(345)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
点击右上角即可分享
微信分享提示