小编典典

Google Chrome打印分页符

css

我正在尝试让Google Chrome浏览器执行分页符。

通过一堆page-break-after:always;在chrome中有效的网站已经告诉我,但即使有一个非常简单的示例,我似乎也无法使其正常工作。使用chrome打印时,有什么方法可以强制分页?


阅读 810

收藏
2020-05-16

共1个答案

小编典典

我已经在包括Chrome在内的所有主要浏览器中成功使用了以下方法:

<!DOCTYPE html>

<html>
  <head>
    <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
    <title>Paginated HTML</title>
    <style type="text/css" media="print">
      div.page
      {
        page-break-after: always;
        page-break-inside: avoid;
      }
    </style>
  </head>
  <body>
    <div class="page">
      <h1>This is Page 1</h1>
    </div>
    <div class="page">
      <h1>This is Page 2</h1>
    </div>
    <div class="page">
      <h1>This is Page 3</h1>
    </div>
  </body>
</html>

这是一个简化的示例。在实际代码中,每个页面div包含更多元素。

2020-05-16