html页面实现A4打印

2019-10-10  本文已影响0人  AAA前端
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
  </head>
  <style>
    body {
      background: rgb(204, 204, 204);
    }
    page[size="A4"] {
      background: white;
      width: 21cm;
      height: 29.7cm;
      display: block;
      margin: 0 auto;
      margin-bottom: 0.5cm;
    }
    @media print {
      body,
      page[size="A4"] {
        margin: 0;
        box-shadow: 0;
      }
    }
  </style>
  <body>
    <page size="A4">
      里面是打印的内容
    </page>
  </body>
</html>

上一篇下一篇

猜你喜欢

热点阅读